Identity-login.js function - Cannot find module 'faunadb' - works in other functions

Hello,
I am stuck on a problem that I can’t get my head around.

I have netlify function identity-login.js where I do:
const faunadb = require('faunadb');

And when trying to login it fails in the log with Cannot find module ‘faunadb’ (full log at the bottom).

But, it does work in other functions like registration (identity-signup.js), no complaints at all.

Is there a problem in identity-login.js that it can’t be used there or what am I missing?

Thank you!

Full log

Feb 7, 07:25:07 PM: INIT_START Runtime Version: nodejs:16.v28 Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:3a370867e1aa01a0dd678120fe6e1db0dea78161534d467823c8e0c4b84246ecFeb 7, 07:25:07 PM: 2024-02-07T18:25:07.503Z undefined ERROR Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'faunadb'\nRequire stack:\n- /var/task/functions/identity-login.js\n- /var/task/identity-login.js\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'faunadb'","Require stack:","- /var/task/functions/identity-login.js","- /var/task/identity-login.js","- /var/runtime/index.mjs"," at _loadUserApp (file:///var/runtime/index.mjs:1087:17)"," at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)"," at async start (file:///var/runtime/index.mjs:1282:23)"," at async file:///var/runtime/index.mjs:1288:1"]}Feb 7, 07:25:07 PM: INIT_REPORT Init Duration: 163.14 ms Phase: init Status: error Error Type: Runtime.ExitErrorFeb 7, 07:25:07 PM: 2024-02-07T18:25:07.687Z undefined ERROR Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'faunadb'\nRequire stack:\n- /var/task/functions/identity-login.js\n- /var/task/identity-login.js\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'faunadb'","Require stack:","- /var/task/functions/identity-login.js","- /var/task/identity-login.js","- /var/runtime/index.mjs"," at _loadUserApp (file:///var/runtime/index.mjs:1087:17)"," at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)"," at async start (file:///var/runtime/index.mjs:1282:23)"," at async file:///var/runtime/index.mjs:1288:1"]}Feb 7, 07:25:07 PM: INIT_REPORT Init Duration: 189.68 ms Phase: invoke Status: error Error Type: Runtime.ExitErrorFeb 7, 07:25:07 PM: Unknown application error occurred Runtime.ImportModuleError

Hi @Sotak,

Thanks for reaching out! Sorry to hear about the issue with functions.

That is weird that it’s working in other functions but not identity-login.js.

As some high level checks:

Could you check the package.json Dependencies : and ensure that faunadb is listed in the dependencies section of your package.json file.

Check that functions are structured correctly within your project. For Netlify Functions, they should be in a directory specified in your Netlify configuration (for example, netlify.toml ) or in the default /functions directory.

Also check to see if f faunadb works locally.

Thank you Melvin,
package.json has the Faunadb, even tried to upgrade to latest.
Functions directory is defined well.

All other functions that have require “faunadb” work well, except this one.

Can you try adding:

[functions]
  node_bundler = "esbuild"

to your netlify.toml?