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.jsduring 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
- router_deployment_not_found
I updated my function a few times and now i am getting the error: router_deployment_not_found I even reverted back to my original code but i am still getting th...
- Usage of the new Client() and dealing wi...
Hey guys, just a quick one - we had some web traffic the other day and it ended up bombing out - To put in perspective of how the app works, we have a Nuxt Ap...
- [Beginner] CLI --queries Syntax Error & ...
Hi everyone! I am a beginner with Appwrite and trying to use the CLI, but I'm stuck with a syntax error. Any guidance would be greatly appreciated! 🙏 **Enviro...