Is it possible to make external API requests from a plugin? I tried with "fetch" but I got a bunch of errors like:
ERROR in ./node_modules/node-fetch/src/index.js
Module not found: Error: Can't resolve 'node:http' in 'C:\Testing\node_modules\node-fetch\src'
@ ./node_modules/node-fetch/src/index.js 9:0-29 52:58-62
@ ./src/index.ts
ERROR in chunk main [entry]
index.js
C:\Testing\node_modules\node-fetch\src\index.js 418bdaf516376824f6a7c1cc01d98479
Unexpected token (271:11)
| if ((body instanceof !(function webpackMissingModule() { var e = new Error("Cannot find module 'node:stream'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())) && (typeof body.getBoundary !== 'function')) {
| // Tee instance body
| p1 = new !(function webpackMissingModule() { var e = new Error("Cannot find module 'node:stream'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())({highWaterMark});
| p2 = new !(function webpackMissingModule() { var e = new Error("Cannot find module 'node:stream'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())({highWaterMark});
| body.pipe(p1);
The code is:
import joplin from 'api';
import fetch from 'node-fetch';
joplin.plugins.register({
onStart: async function() {
const response = await fetch('https://api.github.com/users/github');
const data = await response.json();
console.log(data);
},
});
Thank you.