Back

[SOLVED] Appwrite function can't find node-appwrite module

  • 0
  • Functions
Matej
21 Sep, 2023, 19:19

I deployed new appwrite function in the appwrite cloud, and on execution this is what I get.

TypeScript
Could not load code file.
Error: Cannot find module 'node-appwrite'
Require stack:
- /usr/local/server/src/function/src/index.js
- /usr/local/server/src/server.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:939:15)
    at Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:81:25)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/usr/local/server/src/function/src/index.js:3:25)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:101:39)
TL;DR
The user encountered an issue where the Appwrite function couldn't find the node-appwrite module. They discovered that the issue was caused by using `req.payload` instead of `req.body`. They also updated the tsconfig.json module to ES2022. However, they encountered a new issue where they received a SyntaxError: Unexpected token u in JSON at position 0. It was determined that this was likely a TypeScript issue. The user then mentioned a ReferenceError and a suggestion to rename the file with a .cjs extension. They mentioned trying to deploy a new function and also asked about updating the CLI version. The solution provided was
D5
21 Sep, 2023, 19:27

@Matej Is this a newly deployed function?

D5
21 Sep, 2023, 19:27

Or do you have deployed an update to the corresponding existing function?

Matej
21 Sep, 2023, 19:28

Newly deployed

Matej
21 Sep, 2023, 19:28

from CLI

D5
21 Sep, 2023, 19:29

Are you using new function formatting?

Matej
21 Sep, 2023, 19:30

What's new formating?

Matej
21 Sep, 2023, 19:30

I am using what CLI gave me

D5
21 Sep, 2023, 19:31

Update cli to latest version

D5
21 Sep, 2023, 19:31

And create a new function with CLI so you will get the new format template

Matej
21 Sep, 2023, 19:31

πŸ‘€

Matej
21 Sep, 2023, 19:32

What's the latest cli version and how do I update'

Matej
21 Sep, 2023, 19:33

nvm I updated

D5
21 Sep, 2023, 19:33

Was about to send πŸ˜…

Matej
21 Sep, 2023, 19:34

But, I kind of use new formating in my firstly deployed function anyway πŸ€”

Matej
21 Sep, 2023, 19:34

I'll try to deploy new one and see if it changes anything

Matej
21 Sep, 2023, 19:39

ReferenceError: exports is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and '/usr/local/server/src/function/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. at file:///usr/local/server/src/function/src/main.js:2:23 at ModuleJob.run (node:internal/modules/esm/module_job:198:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:409:24) at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15) at async execute (/usr/local/server/src/server.js:126:32) at async /usr/local/server/src/server.js:158:13

Matej
21 Sep, 2023, 19:39

Ok this is now probably typescript issue

Matej
21 Sep, 2023, 19:40

this is my tsconfig

{ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "outDir": "./src", "rootDir": "./dev", "strict": true, "moduleResolution": "node", "esModuleInterop": true }, "include": [ "dev/**/*", ], "exclude": ["node_modules"] }

Matej
21 Sep, 2023, 19:41

SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>) at Module.default (file:///usr/local/server/src/function/src/main.js:20:26) at execute (/usr/local/server/src/server.js:141:48) at async /usr/local/server/src/server.js:158:13

Making progress. πŸ˜„

Matej
21 Sep, 2023, 19:50

@D5 Ok and I was also doing req.payload instead req.body Along with few hickups here and there, thing are now working. Also updated tsconfig.json module to ES2022

Can close this, ty πŸ™‚

D5
21 Sep, 2023, 19:52

Perfect. Sorry for not replying faster

D5
21 Sep, 2023, 19:52

[SOLVED] Appwrite function can't find node-appwrite module

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