Runtime.ImportModuleError Cannot find module

I have a module that I’m requiring via relative path in a netlify function. All works well using netlify dev cli but when deployed I receive this error:

“errorType”:“Runtime.ImportModuleError”,
“errorMessage”:"Error: Cannot find module ‘…/…/db/insert-row’ …

It’s deployed though github, I checked and the file in question is in the repository.

I have 2 functions that use relative paths for require statements. The first function is working properly on both local & deployed sites. The difference in the 2nd (non-working) function is it requires another javascript file that then requires the file that’s throwing this error.

Does anyone have ideas on how to fix?

Thank you!

Did you give this a try:

No I did not try that. All my imports are using ./ or …/ to traverse directory structure. I’m not using any variables in imports. Strange thing is that other imports to the same files in the same project work just fine

But, does that work or not work?

Any non-module files are usually supposed to be added to functions using that.

I did not see this as a good option as I have many functions and manually configuring each of them would be tedious and should not need to be done because I don’t require dynamic filenames. The paths are hard-coded into the source and the netlify build process should be able to find them. Indeed, it does find those files in some functions and not in others.

That said, I followed a link from the page you suggested to this:

I added this to my netlify.toml file and it seems to fix the issue:

[functions]
node_bundler = “esbuild”

Thank you for the suggestion, while it wasn’t an option fo rme to use that strategy, it did lead me to the fix.

1 Like