Next.js Deploy Error: Cannot find module '../webpack-runtime.js'

We just released a new version of next-multilingual where one of the core change was supporting localized APIs and now the Netlify build is failing (while it is working on Vercel and locally).

The Netlify application is: ttps://next-multilingual.netlify.app

Here is the error log:

6:49:22 PM: ────────────────────────────────────────────────────────────────
6:49:22 PM:   Dependencies installation error                               
6:49:22 PM: ────────────────────────────────────────────────────────────────
6:49:22 PM: ​
6:49:22 PM:   Error message
6:49:22 PM:   A Netlify Function failed to require one of its dependencies.
6:49:22 PM:   Please make sure it is present in the site's top-level "package.json".
​
6:49:22 PM:   In file "/opt/build/repo/.netlify/functions-internal/next_index/next_index.js"
6:49:22 PM:   Cannot find module '../webpack-runtime.js' from '/opt/build/repo/.netlify/functions-internal/next_index/nextPage/pages'

The public repository of the application can be found here: GitHub - Avansai/next-multilingual-example: Standalone `next-multilingual` example application.

Hi @nbouvrette

In your netlify.toml under [functions] could you try adding

node_bundler = "esbuild"

Similar result:

7:53:37 PM:   Error message
7:53:37 PM:   A Netlify Function failed to require one of its dependencies.
7:53:37 PM:   Please make sure it is present in the site's top-level "package.json".
​
7:53:37 PM:   Build failed with 1 error:
7:53:37 PM:   .netlify/functions-internal/next_index/nextPage/pages/index.js:560:34: error: Could not resolve "../webpack-runtime.js"

By the way I just noticed that while the deployment is failing, the endpoint still works:

https://next-multilingual-example-e5wbbkx1w-avansai.vercel.app/

I presume the deployment is not completed because of this:

7:53:38 PM: Finished saving go dependencies

7:53:41 PM: Build failed due to a user error: Build script returned non-zero exit code: 2

7:53:41 PM: Creating deploy upload records

7:53:41 PM: Failing build: Failed to build site

7:53:41 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2

7:53:41 PM: Finished processing build request in 1m36.402741933s

While I am not as proficient in Next.js as many others, I do wonder if using a canary build of Next.js is (in part) causing part of the issues (i.e. "next": "^11.1.3-canary.97", from the package.json.) Last I knew, Next.js 11.1.2 support was still beta/experimental in the netlify-plugin-nextjs.

The actual running build (on https://next-multilingual.netlify.app/) is using 11.1.3-canary.41

I know I am pushing it a bit using bleeding-edge builds here, but it is working well on Vercel and locally so I thought I would still check if there was any change here since my latest build.

I also had issues the first time I deployed Next but we managed to fix it.

Thanks

True. But unless people use the latest (I love testing beta/canary/pre-production of anything) it is hard to move things forward.

Working on Vercel is different to working on Netlify. They are different platforms, different methodologies, etc. Next.js is developed/maintained by Vercel, so they will always have the upperhand when it comes to supporting the latest builds/features. (This is purely my opinion. I neither speak for Netlify or Vercel.)

Have you checked you are using the latest plugin version as @ascorbic mentioned in the your previous thread?

Am sure Support/Software Engineering teams are much better placed than I to provide support here.

Hey there, @nbouvrette :wave:

Seconding @coelmay here, have you checked that you’re using the latest plugin version? Additionally, I recommend bringing this conversation to the Beta V4 thread on our repo. This is a direct connection to the NextJS experts at Netlify!

Let us know if you have further questions.

Sorry, I didn’t have a chance yet, will try as soon as possible and circle back!

Sounds great, thanks for letting us know!

I used this:

[build]
  command = "npm run build"
  publish = ".next"

[[plugins]]
  package = "@netlify/plugin-nextjs-experimental"

[functions]
  included_files = [".next/*.json"]

Also did this npm install -D @netlify/plugin-nextjs-experimental

And I am getting the following error:

1:03:46 PM: ────────────────────────────────────────────────────────────────
1:03:46 PM:   Dependencies installation error                               
1:03:46 PM: ────────────────────────────────────────────────────────────────
1:03:46 PM: ​
1:03:46 PM:   Error message
1:03:46 PM:   A Netlify Function failed to require one of its dependencies.
1:03:46 PM:   Please make sure it is present in the site's top-level "package.json".
​
1:03:46 PM:   In file "/opt/build/repo/.netlify/functions-internal/next_index/next_index.js"
1:03:46 PM:   Cannot find module '../webpack-runtime.js' from '/opt/build/repo/.netlify/functions-internal/next_index/nextPage/pages'

:wave: @nbouvrette

Can you give the two solutions in this Stack Overflow thread a try and see if they help? You can also try adding webpack to your package.json.

Let us know how it goes!

Hi @audrey - I am not sure I understand which value I should put in my webpack entries?

I tried to install webpack as a dev dependency and got the same error.

I also thought this might be related to this open issue: next@canary - can't find module "webpack5" · Issue #30167 · vercel/next.js · GitHub

I downgraded Next.js to version 11.1.3-canary.67 and still got the same error.

Hey there, @nbouvrette :wave:

Thanks for letting us know. I’m still not seeing that you used the most recent beta plugin in your above messages. Can you please upgrade to our newest plugin? In your post from 8 days ago it looks like you were still using the @netlify/plugin-nextjs-experimental.

Sorry for the late reply @hillary - I thought that I initially started without using the experimental plugin and then tried that one and the result was both the same - unless there is something else I need to do to try the most recent beta plugin?

Just to be sure I re-run a build, with both Next.js canary.67 and I am getting the same error.

Hey there, @nbouvrette :wave:

Great question. Thanks for confirming!

When I look at your .toml file it looks like you’re using

[[plugins]]
package = "@netlify/plugin-nextjs"

However, it looks like you are missing
npm install -D @netlify/plugin-nextjs@beta from your package.json.

Here is a link to the beta repo that outlines what you need to install to use the beta version.

Let me know if this clears things up for you :slight_smile:

Thanks @hillary I made some progress. Now there are no more deployment errors but the site returns a 500:

I noticed in the log there seem to be a lot of redirects? In my repo I add a lot of other redirects in the Nex.js config… not sure if it’s related to not.

Given we have been troubleshooting this for weeks, may I suggest that you fork my repo? I suspect you would probably be able to pinpoint the issue better than me :slight_smile:

Hey @nbouvrette,

Looks like the exact same steps worked for some other user: Dependencies installation error Cannot find module '../webpack-runtime.js'

Unfortunately, we can’t provide support on your code-level, but seeing that it’s working for someone else, maybe it would work for you too?

We discussed this with our devs one more time and we were told that the latest version of the plugin beta7 would log in the build log in case you have anything leftover from the previous version’s functions. This might be a good place to try.

Also, about the 500s, you should try checking the function logs as soon as you get the error to see what it says. Once we have the logs, we can debug it accordingly.

1 Like

I didn’t know about the function logs but the error was pretty clear, I needed to add the NEXT_PUBLIC_ORIGIN environment variable.

The strange thing on the other hand, is that this variable is already available in the repository: next-multilingual-example/.env.production at main · Avansai/next-multilingual-example · GitHub

I know that the URL is the one we use for Vercel, but it should not have triggered this error. Are you integrated with the .env files that Next.js uses?

The site is back online, thanks for your help!

1 Like