Got a "Cannot find module" error, tried fixes from other threads

App: (You can see the error yourself by filling out those three fields and clicking Submit, the form POSTs to the function that errors out.

Everything builds fine, but when accessing the function for the first time I get the following:

That internal ID is: 01HHJC43VKBE32TTCVQA9TWE0T

I’ve gone through a bunch of the threads here with a similar issue, and this is what I’ve tried so far:

  • Everything funs fine in netlify dev
  • No errors with netlify build or netlify build --offline
  • I’ve only got one package.json in the root of my app
  • mysql2 is definitely listed in package.json
  • Added external_node_modules = ["mysql2"] to my [functions] heading in netlify.toml
  • Added node_bundler = "esbuild" to [functions]
  • Forced an npm install in my build command

I have no real build step other than running the tailwind CLI to compile my one CSS file.

Solved it! I had a couple of included files from my /lib directory that were using require instead of import (I converted from CommonJS to ESM half-way through the project).

1 Like