NextJS App Build Fails

I’ve been away for awhile. I come back and my NextJS app no longer builds on Netlify (it does build locally). The error message links to an internal dependency:

2:24:29 PM: ./node_modules/@aws-sdk/client-sso-oidc/dist-cjs/protocols/Aws_restJson1.js 13:37
2:24:29 PM: Module parse failed: Unexpected token (13:37)
2:24:29 PM: You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See
2:24:29 PM: |         "content-type": "application/json",
2:24:29 PM: |     };
2:24:29 PM: >     const resolvedPath = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + "/token";
2:24:29 PM: |     let body;
2:24:29 PM: |     body = JSON.stringify({
2:24:29 PM: > Build error occurred
2:24:29 PM: Error: > Build failed because of webpack errors
2:24:29 PM:     at /opt/build/repo/node_modules/next/dist/build/index.js:15:918
2:24:29 PM:     at async /opt/build/repo/node_modules/next/dist/build/tracer.js:1:1441

What is the nature of the error? The message is not clear to me.

Deploy URL: Netlify App
Deploy ID: 63a45a40a943800008452a0d

Context: Deploy Preview
Deployment Type: (What is this?)
Last Broken Deploy URL: Netlify App
Last Successful Deploy URL: Netlify App

You’re using optional chaining ?. in Node 12 while that was added since Node 14. You need to update your Node Version.

On a side note, you’re using Next 10 along with outdated version of our Next.js Runtime. None of this is actively supported and we cannot provide much support for that.

I have made a few updates to my dependencies and attempted a new deploy. I have added a NODE_VERSION environmental variable in order to ensure I am using Node.js 19.3.0. However, now I am getting a series of error messages that I cannot understand:

I have set an NPM_FLAGS environmental variable in order to pass --legacy-peer-deps to the npm install command, but I don’t see any evidence that this has been received. Is there any way to tell?

Not sure if node_gyp supports Node 19 yet:

I’d advise you to use Node 18 or lower for now.

Thanks for the reply. I have had to downgrade to Node 14.18.1 for the moment in order to get a stable build. My build passes, but I have an issue with the Netflify plugin :

5:59:36 PM:   Error message
5:59:36 PM:   TypeError: Cannot read properties of undefined (reading 'length')
5:59:36 PM: ​
5:59:36 PM:   Plugin details
5:59:36 PM:   Package:        @netlify/plugin-nextjs
5:59:36 PM:   Version:        4.29.4
5:59:36 PM:   Repository:     git+
5:59:36 PM:   npm link:
5:59:36 PM:   Report issues:
5:59:36 PM: ​
5:59:36 PM:   Error location
5:59:36 PM:   In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app
5:59:36 PM:       at join (/opt/build/repo/.netlify/plugins/node_modules/pathe/dist/index.cjs:57:13)
5:59:36 PM:       at getApiRouteConfigs (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/helpers/functions.js:131:39)
5:59:36 PM:       at async getExtendedApiRouteConfigs (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/helpers/functions.js:143:30)
5:59:38 PM: Failed during stage 'building site': Build script returned non-zero exit code: 3 (
5:59:36 PM:       at async onBuild (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/index.js:94:27)
5:59:36 PM:       at async (file:///opt/buildhome/node-deps/node_modules/@netlify/build/lib/plugins/child/run.js:14:5)
5:59:36 PM:       at async handleEvent (file:///opt/buildhome/node-deps/node_modules/@netlify/build/lib/plugins/child/main.js:28:42)
5:59:36 PM:       at async process.<anonymous> (file:///opt/buildhome/node-deps/node_modules/@netlify/build/lib/plugins/ipc.js:91:24)

That’s probably because of this log line:

Yes. Unfortunately, when moving back to version 3 of the plugin, I see a message that I have to upgrade my Next.js version to atleast 10.0.6. And when I do that, I get the same error message we saw at the beginning of this thread:

Keep in mind this is not my code, it’s in the node_modules dependencies.

As far as I can see, you’re now using Node 14: Netlify App (while previously you were using Node 12). Since this is still happening with Node 14, I think you should reach out to the library’s authors to get it fixed (assuming it’s a problem with the dependency). Next 10 is an outdated version and we no longer provide active support for it, so if it’s some Next.js’ problem (or even of Next.js on Netlify specifically), we do not have any useful advice.

I appreciate your responses. I have fixed this problem by doing what I really didn’t want to do, updating to Next.js 13. I also changed a problematic dependency, material-ui-grid, to the proper replacement, @mui/x-data-grid. I was able to take the starter project for Next.js 13, and add my project in, page by page. Now everything compiles correctly, I’m using Node.js 19.3.0, and the latest version of the Netlify Next.js plugin. Thanks again for your help.

1 Like