Back

Getting this Error [ERR_REQUIRE_ESM]; when executing function starter-template

  • 2
  • Functions
  • Cloud
another
14 Sep, 2023, 08:01

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

TL;DR
The user is experiencing an error when executing the function starter-template. They are getting the error [ERR_REQUIRE_ESM]. The error is caused by running Appwrite 1.4.x style functions on previous versions. To resolve this, they need to create a new function using an older version of the CLI, specifically version 2.0.2. They can install this version with `npm install -g appwrite-cli@2.0.2`.
loks0n
15 Sep, 2023, 07:35

👋

another
15 Sep, 2023, 07:35

<:appwriteraisehand:946072255279034388>

loks0n
15 Sep, 2023, 07:35

How did you create the function? Which Node.JS runtime version are you using? Are you using cloud or self-hosted?

another
15 Sep, 2023, 07:36

i created the function using appwrite cli node 18 cloud

loks0n
15 Sep, 2023, 07:41

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

another
15 Sep, 2023, 07:43

ok let me install this versionof cli then

loks0n
15 Sep, 2023, 07:44

Nice! Once you've got this you can initialise a new function, and the template should be working on cloud 👍

another
15 Sep, 2023, 07:44

Why you guys removed old functions guide from appwrite docs?

loks0n
15 Sep, 2023, 07:47

It was updated to cover 1.4.x functions and we've had some difficulty migrating cloud in the meantime.

another
15 Sep, 2023, 07:47

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

loks0n
15 Sep, 2023, 07:48

Valid point, let me tag @VincentGe - should we show old functions guides under version dropdown?

loks0n
15 Sep, 2023, 07:51

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

another
15 Sep, 2023, 07:52

Thank you

VincentGe
15 Sep, 2023, 13:26

We don't support versioning in guides, unfortunately 😅 It was never intended that we have more than one version actively used

VincentGe
15 Sep, 2023, 13:26

but might have been useful

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more