Deploy failed due to an error in @netlify/plugin-nextjs plugin. TypeError: Cannot read properties of undefined (reading 'length'

site name. Example: tatuga-camp.netlify.app
here is the Deploy summary

Plugin "@netlify/plugin-nextjs" internal error
TypeError: Cannot read properties of undefined (reading 'length')
In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app at join (/opt/build/repo/.netlify/plugins/node_modules/pathe/dist/index.cjs:57:13) at traceRequiredServerFiles (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/helpers/functions.js:156:41) at async Promise.all (index 0) at async getAPIPRouteCommonDependencies (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/helpers/functions.js:195:18) at async getAPILambdas (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/helpers/functions.js:221:32) at async onBuild (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/index.js:96:15) at async Object.run (file:///opt/buildhome/node-deps/node_modules/@netlify/build/lib/plugins/child/run.js:14:5) at async handleEvent (file:///opt/buildhome/node-deps/node_modules/@netlify/build/lib/plugins/child/main.js:28:42) at async process.<anonymous> (file:///opt/buildhome/node-deps/node_modules/@netlify/build/lib/plugins/ipc.js:91:24)

here is my JSON file

{
  "name": "tatuga",
  "version": "0.1.0",
  "private": true,
  "browser": {
    "child_process": false
  },
  "scripts": {
    "dev": "next dev -p 8080",
    "start": "next start -p 8080",
    "build": "next build",
    "lint": "next lint"
  },
  "dependencies": {
    "@animxyz/core": "^0.6.6",
    "@emotion/react": "^11.9.3",
    "@emotion/styled": "^11.9.3",
    "@headlessui/react": "^1.7.7",
    "@hookform/resolvers": "^2.9.11",
    "@lottiefiles/lottie-player": "^1.5.7",
    "@lottiefiles/react-lottie-player": "^3.5.2",
    "@mui/icons-material": "^5.8.4",
    "@mui/material": "^5.8.7",
    "@next/font": "^13.0.0",
    "@portabletext/react": "^2.0.0",
    "@prisma/client": "^4.8.1",
    "@sanity/image-url": "^1.0.1",
    "@tinymce/tinymce-react": "^4.3.0",
    "axios": "^0.27.2",
    "image-size": "^1.0.2",
    "lightbox.js-react": "^0.6.4",
    "lottie-react": "^2.3.1",
    "next": "^12.2.5",
    "next-sanity": "^1.0.1",
    "next-sanity-image": "^5.0.0",
    "next-share": "^0.19.0",
    "plaiceholder": "^2.5.0",
    "react": "18.2.0",
    "react-confetti": "^6.1.0",
    "react-dom": "18.2.0",
    "react-full-screen": "^1.1.1",
    "react-icons": "^4.7.1",
    "react-intersection-observer": "^9.4.0",
    "react-messenger-chat-plugin": "^3.0.5",
    "react-player": "^2.11.0",
    "react-query": "^4.0.0-beta.23",
    "react-spring": "^9.7.1",
    "react-use": "^17.4.0",
    "sharp": "^0.32.1",
    "sitemap": "^7.1.1",
    "stripe": "^11.8.0",
    "sweetalert2": "^11.6.2",
    "swiper": "^8.4.4",
    "unist-util-visit": "^4.1.2",
    "use-sound": "^4.0.1",
    "uuid": "^9.0.0",
    "yup": "^1.0.0"
  },
  "devDependencies": {
    "autoprefixer": "^10.4.13",
    "eslint": "8.19.0",
    "eslint-config-next": "12.2.1",
    "file-loader": "^6.2.0",
    "postcss": "^8.4.14",
    "tailwindcss": "^3.1.5",
    "url-loader": "^4.1.1"
  }
}

I don’t know why this error occurs, I have had no problem with deploying my next project to Netifly until now. There is no problem when I run npm build but when I deploy to Netlify, the error occurs I tried to redeploy with the current branch but still not working!

Here is the deploy log on building stage that throws error

4:57:44 PM: @netlify/plugin-nextjs (onBuild event)                        
4:57:44 PM: ────────────────────────────────────────────────────────────────
4:57:44 PM: ​
4:57:44 PM: ​
4:57:44 PM: Plugin "@netlify/plugin-nextjs" internal error                
4:57:44 PM: ────────────────────────────────────────────────────────────────
4:57:44 PM: ​
4:57:44 PM:   Error message
4:57:44 PM:   TypeError: Cannot read properties of undefined (reading 'length')
4:57:44 PM: ​
4:57:44 PM:   Plugin details
4:57:44 PM:   Package:        @netlify/plugin-nextjs
4:57:44 PM:   Version:        4.37.1
4:57:44 PM:   Repository:     git+https://github.com/netlify/next-runtime.git
4:57:44 PM:   npm link:       https://www.npmjs.com/package/@netlify/plugin-nextjs
4:57:44 PM:   Report issues:  https://github.com/netlify/next-runtime/issues
4:57:44 PM: ​
4:57:44 PM:   Error location
4:57:44 PM:   In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app
4:57:44 PM:       at join (/opt/build/repo/.netlify/plugins/node_modules/pathe/dist/index.cjs:57:13)
4:57:44 PM:       at traceRequiredServerFiles (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/helpers/functions.js:156:41)
4:57:44 PM:       at async Promise.all (index 0)
4:57:44 PM:       at async getAPIPRouteCommonDependencies (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/helpers/functions.js:195:18)
4:57:44 PM:       at async getAPILambdas (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/helpers/functions.js:221:32)
4:57:44 PM:       at async onBuild (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/lib/index.js:96:15)
4:57:44 PM:       at async Object.run (file:///opt/buildhome/node-deps/node_modules/@netlify/build/lib/plugins/child/run.js:14:5)
4:57:44 PM:       at async handleEvent (file:///opt/buildhome/node-deps/node_modules/@netlify/build/lib/plugins/child/main.js:28:42)
4:57:44 PM:       at async process.<anonymous> (file:///opt/buildhome/node-deps/node_modules/@netlify/build/lib/plugins/ipc.js:91:24)
4:57:44 PM: ​
4:57:44 PM:   Resolved config
4:57:44 PM:   build:
4:57:44 PM:     command: npm run build
4:57:44 PM:     commandOrigin: ui
4:57:44 PM:     environment:
4:57:44 PM:       - NEXTAUTH_SECRET
4:57:44 PM:       - NEXTAUTH_URL
4:57:44 PM:       - NEXT_PUBLIC_LIGHTBOX_KEY
4:57:44 PM:       - NEXT_PUBLIC_SANITY_DATASET
4:57:44 PM:       - NEXT_PUBLIC_SANITY_PROJECT_ID
4:57:44 PM:       - NEXT_PUBLIC_TINY_TEXTEDITOR_KEY
4:57:44 PM:       - SANITY_WRITE_TOKEN
4:57:44 PM:       - Server_Url
4:57:44 PM:       - NEXT_PRIVATE_TARGET
4:57:44 PM:     publish: /opt/build/repo/.next
4:57:44 PM:     publishOrigin: ui
4:57:44 PM:   plugins:
4:57:44 PM:     - inputs: {}
4:57:44 PM:       origin: ui
4:57:44 PM:       package: '@netlify/plugin-nextjs'
4:57:48 PM: Failed during stage 'building site': Build script returned non-zero exit code: 3 (https://ntl.fyi/exit-code-3)
4:57:48 PM: Build failed due to a plugin error: Build script returned non-zero exit code: 3
4:57:48 PM: Failing build: Failed to build site
4:57:49 PM: Finished processing build request in 2m2.91s

Hi @permlap,

Thanks for reaching out!

I’m showing that your latest build was successful. Were you able to resolve the issue?

Yes, It has been solved by installing package @netlify/plugin-nextjs on my nextjs project. But I still have no idea why this error suddenly occurs. My site has always been deployed to Netlify successfully without needing to install package @netlify/plugin-nextjs on my nextjs project.

thanks for coming back and sharing your specific solution with the community!

This has happened for me too. Installing the package locally in my project did not work. What has suddenly changed with the builds?

Please share the site name @mali89.

Is there some way to DM you the site name @hrishikesh

Upgrading plugin-nextjs fixed the issue for us. How can it be that one day we wake up and all webhooks are suddenly not working for customers? @hrishikesh

Please inbox at @support we can’t provide an exact reason why this is working now without this info, but I’m glad you got the issue fixed.