
Probably a silly question, but Im not able to use fetch() with node-fetch
inside a NodeJS Appwrite function. I've try this :
const fetch = require("node-fetch");
But I got an error :
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /usr/code-start/node_modules/node-fetch/src/index.js
require() of ES modules is not supported.
require() of /usr/code-start/node_modules/node-fetch/src/index.js from /usr/code-start/src/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /usr/code-start/node_modules/node-fetch/src/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /usr/code-start/node_modules/node-fetch/package.json.
How im supposed to add fetch in my function ? Ive try to renaming index.js
to index.cjs
like the error said but appwrite dont find index.js
during execution...

How did you initialize your function?

There is my function :
const appwriteSDK = require("node-appwrite");
const fetch = require("node-fetch");
const novuSDK = require("@novu/node")
module.exports = async function (req, res) {
....
Well its working with this version of node-fetch : "node-fetch": "^2.6.12"
but not with the latest

So you didn't initialize the function using the Appwrite CLI (appwrite init function
)?

yes i did that

What version of node?

Did you change the package.json file created by the init?

Actually never mind. Downgrading is the right approach. Node-fetch v3 is incompatible

[SOLVED] Usgin fetch inside Appwrite function

[SOLVED] Using fetch inside Appwrite function
Recommended threads
- Accessing caller UserID on Function Exce...
I'm working with function, which should generate a document in Collection B, but only if user who's calling the function, is the owner of Document in Collection...
- Login redirect going to http not https
Hi yall, I'm having an issue where the redirect URL is going to http, instead of https. I think this is a bug. ``` https://accounts.google.com/o/oauth2/v2/auth...
- Can't sign in after upgrade
I used the upgrade code in from the documents but now I can't sign in I get this log document error that gets cut off,
