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
- Getting “Internal Error 500” for all ser...
SDK error is “Access to this resource is block” - but the credentials and same script was working fine before (there’s been no changes my side). The Console sys...
- Error deploying on appwrite site
Hello. I'm learning to program in Flutter, and after creating my first app, I concluded that I would use AppWrite as the backend. So, I created a very simple a...
- DATABASE ERROR
When I select NULL as the value and click update, it shows that the update is successful, but when I refresh it changes back to add-avatar. It seems that all fi...
