Getting this Error [ERR_REQUIRE_ESM]; when executing function starter-template
- 2
- Functions
- Cloud
main.js ``` // import { Client } from 'node-appwrite';
// This is your Appwrite function // It's executed each time we get a request export default async ({ req, res, log, error }) => { // Why not try the Appwrite SDK? // // const client = new Client() // .setEndpoint('https://cloud.appwrite.io/v1') // .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) // .setKey(process.env.APPWRITE_API_KEY);
// You can log messages to the console log('Hello, Logs!');
// If something goes wrong, log an error error('Hello, Errors!');
// The req
object contains the request data
if (req.method === 'GET') {
// Send a response with the res object helpers
// res.send()
dispatches a string back to the client
return res.send('Hello, World!');
}
// res.json()
is a handy helper for sending JSON
return res.json({
motto: 'Build Fast. Scale Big. All in One Place.',
learn: 'https://appwrite.io/docs',
connect: 'https://appwrite.io/discord',
getInspired: 'https://builtwith.appwrite.io',
});```
error Error [ERR_REQUIRE_ESM]: require() of ES Module /usr/code-start/src/main.js from /usr/local/src/server.js not supported.
Instead change the require of main.js in /usr/local/src/server.js to a dynamic import() which is available in all CommonJS modules.
at Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39)
at /usr/local/src/server.js:55:28
👋
<:appwriteraisehand:946072255279034388>
How did you create the function? Which Node.JS runtime version are you using? Are you using cloud or self-hosted?
i created the function using appwrite cli node 18 cloud
This error is caused by running Appwrite 1.4.x style functions on previous versions
Unfortunately, we haven't yet updated cloud to Appwrite 1.4 , but we promise it's coming very soon 🤞
To get this working, you'll want to create a new function using an older version of the CLI, version 2.0.2 should work. You can install it with npm install -g appwrite-cli@2.0.2
ok let me install this versionof cli then
Nice! Once you've got this you can initialise a new function, and the template should be working on cloud 👍
Why you guys removed old functions guide from appwrite docs?
It was updated to cover 1.4.x functions and we've had some difficulty migrating cloud in the meantime.
i am not able to find the guide which used to show about req.variables stuff, that's why i got confuse and thought that i have to migrate to new functions
Valid point, let me tag @VincentGe - should we show old functions guides under version dropdown?
It's not ideal, but if you really need to old docs urgently you can browse the source code from our git history https://github.com/appwrite/docs/blob/1.28.2/app/views/docs/functions.phtml
Thank you
We don't support versioning in guides, unfortunately 😅 It was never intended that we have more than one version actively used
but might have been useful
Recommended threads
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...
- Function in Node.JS to monitor events ar...
Hello everyone. I'm creating my first Node.JS function, but I don't have much experience with node and javascript. I'm trying to create a function, that monito...