chelaxe
@chelaxe
инженер-программист

"TypeError: fetch is not a function". Как быть?

NODE.JS v5.4.0
Установлен openpgp модуль:
npm install --save openpgp

Имеется такой код:
var openpgp = require('openpgp');
var hkp = new openpgp.HKP('https://pgp.mit.edu');
hkp.lookup({
    query: 'alice@example.com'
}).then(function(key) {
    var publicKey = openpgp.key.readArmored(key);
});


Получаю ошибку:
return fetch(uri).then(function(response) {
TypeError: fetch is not a function
    at HKP.lookup (*\node_modules\openpgp\src\hkp\hkp.js:63:10)


fetch is not a function - как побороть? Гугл меня не спасает...
  • Вопрос задан
  • 3316 просмотров
Решения вопроса 1
chelaxe
@chelaxe Автор вопроса
инженер-программист
Решение. Спасибо Алексею Уколову на то что обратил мое внимание на пропущенный абзац.
var fetch = typeof window !== 'undefined' ? window.fetch : require('node-fetch');
var hkp = new openpgp.HKP('https://pgp.mit.edu', fetch);

Ну и ставим "node-fetch"
npm install --save node-fetch
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
For the OpenPGP HTTP Key Server (HKP) client the new fetch api is used. There is a polyfill for both browsers and node.js runtimes. These are not bundled in the library however and users must add these themselves. See the unit tests for examples of how to integrate them.
https://github.com/openpgpjs/openpgpjs#dependencies
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы