Answer the question
In order to leave comments, you need to log in
"TypeError: fetch is not a function". How to be?
NODE.JS v5.4.0
Installed openpgp module: npm install --save openpgp
There is this code:
var openpgp = require('openpgp');
var hkp = new openpgp.HKP('https://pgp.mit.edu');
hkp.lookup({
query: '[email protected]'
}).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)
Answer the question
In order to leave comments, you need to log in
Decision. Thanks to Alexey Ukolov for drawing my attention to the missing paragraph.
var fetch = typeof window !== 'undefined' ? window.fetch : require('node-fetch');
var hkp = new openpgp.HKP('https://pgp.mit.edu', fetch);
npm install --save node-fetch
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question