Error: Cannot find module 'node-fetch'

hello, I’m new at using your lambda functions. At the top of my code I have:

const fetch = require('node-fetch').default (I've also tried without default. I installed the npm encoding package, but I'm still getting the screenshot error.

The site itself appears to work (https://joyful-zuccutto-8b8329.netlify.app/), but https://joyful-zuccutto-8b8329.netlify.app/.netlify/functions/meta does not.

I don’t see errors in the deploy log is :

8:28:29 PM: Starting post processing
8:28:29 PM: Post processing - HTML
8:28:29 PM: Post processing - header rules
8:28:29 PM: Post processing - redirect rules
8:28:30 PM: Post processing done
8:28:30 PM: Section completed: postprocessing
8:28:30 PM: Site is live :sparkles:

The function log:

Jan 22, 08:43:44 PM: 2023-01-23T01:43:44.152Z undefined ERROR Uncaught Exception {“errorType”:“Runtime.ImportModuleError”,“errorMessage”:“Error: Cannot find module ‘node-fetch’\nRequire stack:\n- /var/task/meta.js\n- /var/runtime/index.mjs”,“stack”:[“Runtime.ImportModuleError: Error: Cannot find module ‘node-fetch’”,“Require stack:”,“- /var/task/meta.js”,“- /var/runtime/index.mjs”," at _loadUserApp (file:///var/runtime/index.mjs:1000:17)“,” at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1035:21)“,” at async start (file:///var/runtime/index.mjs:1200:23)“,” at async file:///var/runtime/index.mjs:1206:1"]}
Jan 22, 08:43:44 PM: Unknown application error occurred
Runtime.ImportModuleError
Jan 22, 08:43:44 PM: 6af71b08 Duration: 178.80 ms Memory Usage: 13 MB
Jan 22, 08:43:44 PM: INIT_START Runtime Version: nodejs:16.v11 Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:ee071345fbee0f4751fcbcd47a5784052d8f7d4256ca7f31e6056b294cee515c
Jan 22, 08:43:44 PM: 2023-01-23T01:43:44.363Z undefined ERROR Uncaught Exception {“errorType”:“Runtime.ImportModuleError”,“errorMessage”:“Error: Cannot find module ‘node-fetch’\nRequire stack:\n- /var/task/meta.js\n- /var/runtime/index.mjs”,“stack”:[“Runtime.ImportModuleError: Error: Cannot find module ‘node-fetch’”,“Require stack:”,“- /var/task/meta.js”,“- /var/runtime/index.mjs”," at _loadUserApp (file:///var/runtime/index.mjs:1000:17)“,” at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1035:21)“,” at async start (file:///var/runtime/index.mjs:1200:23)“,” at async file:///var/runtime/index.mjs:1206:1"]}

Build settings:

Build settings
Base directory
Not set
Build command

no build command

Publish directory
Public
Deploy log visibility
Logs are public
Build status
Active

Hope that is enouph info - Thank you in advance!

Hiya @kc1 :wave:t6: , welcome to the forums and thanks so much for reaching out.

Do you think you can give these two support guides a read and see if this helps solve your problem. Netlify Functions Can’t find module and Cannot use node-fetch in lambda function .

Thank you - In my case I downgraded to node-fetch 2.6.1 - the last release using commonjs - This solved the problem.

1 Like

Perfect glad to hear it’s working and you found a workaround. (;