Netlify function "Cannot find module '@octokit/core'"

Hi,

I start getting the following error while using netlify function:

Feb 12, 04:30:23 PM: c57193e6 2023-02-12T15:30:24.660Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module '@octokit/core'\nRequire stack:\n- /var/task/functions/colab.js\n- /var/task/colab.js\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module '@octokit/core'","Require stack:","- /var/task/functions/colab.js","- /var/task/colab.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"]}
Feb 12, 04:30:23 PM: c57193e6 2023-02-12T15:30:24.916Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module '@octokit/core'\nRequire stack:\n- /var/task/functions/colab.js\n- /var/task/colab.js\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module '@octokit/core'","Require stack:","- /var/task/functions/colab.js","- /var/task/colab.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"]}
Feb 12, 04:30:23 PM: c57193e6 Unknown application error occurred
Feb 12, 04:30:23 PM: c57193e6 Runtime.ImportModuleError
Feb 12, 04:30:24 PM: c57193e6 Duration: 222.19 ms	Memory Usage: 15 MB	

However if tested locally with netlify dev, the error does not happen and everything is working as expected.

More info how things are coded and configured:

  • netlify.toml
  • functions/colab.js

Code:

Deployment:

Any hints please
Thanks !

Hi @vfdev-5,

Thanks for reaching out!

I found this Netlify Forum post that has two possible solutions. The error in the post is similar, does either solution work for you?

Thanks for the links @Melvin
Second solution of using node_bundler = “esbuild” is already done in my case.
And about the path and including files, as octokit is a node module and not our local file, I think it may be not applicable…

hmm can I ask what else you’ve tried?

Well, a lot of various things.

Here is a minimal repro repository:

Clicking on “Run custom function as netlify” will result to a similar issue:

 Runtime.ImportModuleError - Error: Cannot find module '@octokit/core' Require stack: - /var/task/functions/func1.js - /var/task/func1.js - /var/runtime/index.mjs 

However, we can run the same code on the frontend without issues…

I deployed your code and it appears to work: https://f-85329.netlify.app/.netlify/functions/func1
Repo: GitHub - Hrishikesh-K/f-85329

1 Like

Thanks @hrishikesh for your answer and the code changes. I asked few questions in the code about the change. I could update main project with your suggestions and it works now. Thanks!

hi @vfdev-5 :wave:t6: , i’m glad to hear you wee able to resolve your issue! (;