Skip to content
Back

[SOLVED] Relative imports not allowed in writing functions in JS

  • 0
  • Functions
sswastik02
23 Dec, 2023, 02:37

I tried creating a function from appwrite using npx appwrite init function , I created a file auth.js which I imported in main.js. But I get the error during execution:

TypeScript
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/usr/local/server/src/function/src/auth' imported from /usr/local/server/src/function/src/main.js
    at new NodeError (node:internal/errors:372:5)
    at finalizeResolution (node:internal/modules/esm/resolve:405:11)
    at moduleResolve (node:internal/modules/esm/resolve:966:10)
    at defaultResolve (node:internal/modules/esm/resolve:1176:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:605:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:318:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
    at link (node:internal/modules/esm/module_job:78:36)
TL;DR
I created a function in JS using `npx appwrite init function`, which resulted in a relative import error. The error was `Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/usr/local/server/src/function/src/auth' imported from /usr/local/server/src/function/src/main.js`. The solution to this issue is to include the file extension (.js) along with the import statement.
sswastik02
23 Dec, 2023, 08:45

We have to also include the extension along with the import statement to make it work. The issue is solved for now

sswastik02
23 Dec, 2023, 08:45

[SOLVED] Relative imports not allowed in writing functions in JS

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