Plugin "@netlify/plugin-nextjs" failed error

Site name: https://hady-mat.netlify.app/
Error: Plugin “@netlify/plugin-nextjs” failed

So I downloaded a ReactJS Template from Envato it’s working fine on my localhost but give an error failed to build Plugin “@netlify/plugin-nextjs” failed I went through the previous questions but didn’t find an answer.

1:39:32 PM: Build ready to start
1:39:34 PM: build-image version: c5b01a919d3e16af69445c5de0cacb49efbb1a23 (focal)
1:39:34 PM: build-image tag: v4.4.0
1:39:34 PM: buildbot version: 32ed0189d752047ee8dfb652c26d682ee00f88d8
1:39:34 PM: Building without cache
1:39:34 PM: Starting to prepare the repo for build
1:39:35 PM: No cached dependencies found. Cloning fresh repo
1:39:35 PM: git clone https://github.com/YasirRWebDesigner/files
1:39:35 PM: Preparing Git Reference refs/heads/main
1:39:36 PM: Parsing package.json dependencies
1:39:37 PM: Starting build script
1:39:37 PM: Installing dependencies
1:39:37 PM: Python version set to 2.7
1:39:37 PM: Downloading and installing node v14.18.1...
1:39:38 PM: Downloading https://nodejs.org/dist/v14.18.1/node-v14.18.1-linux-x64.tar.xz...
1:39:38 PM: Computing checksum with sha256sum
1:39:38 PM: Checksums matched!
1:39:41 PM: Now using node v14.18.1 (npm v6.14.15)
1:39:41 PM: Started restoring cached build plugins
1:39:41 PM: Finished restoring cached build plugins
1:39:41 PM: Attempting ruby version 2.7.2, read from environment
1:39:43 PM: Using ruby version 2.7.2
1:39:43 PM: Using PHP version 8.0
1:39:43 PM: Started restoring cached yarn cache
1:39:43 PM: Finished restoring cached yarn cache
1:39:43 PM: Installing yarn at version 1.22.10
1:39:43 PM: Installing Yarn!
1:39:43 PM: > Downloading tarball...
1:39:43 PM: [1/2]: https://yarnpkg.com/downloads/1.22.10/yarn-v1.22.10.tar.gz --> /tmp/yarn.tar.gz.WKICmZTBTI
1:39:43 PM:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
1:39:43 PM:                                  Dload  Upload   Total   Spent    Left  Speed
1:39:43 PM:   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
1:39:43 PM: 100    81  100    81    0     0    786      0 --:--:-- --:--:-- --:--:--   778
1:39:43 PM: 100    81  100    81    0     0    778      0 --:--:-- --:--:-- --:--:--   778
1:39:43 PM: 100    95  100    95    0     0    257      0 --:--:-- --:--:-- --:--:--   257
1:39:44 PM: 100   626  100   626    0     0   1337      0 --:--:-- --:--:-- --:--:--  1337
1:39:44 PM: 100 1215k  100 1215k    0     0  2118k      0 --:--:-- --:--:-- --:--:-- 2118k
1:39:44 PM: [2/2]: https://yarnpkg.com/downloads/1.22.10/yarn-v1.22.10.tar.gz.asc --> /tmp/yarn.tar.gz.WKICmZTBTI.asc
1:39:44 PM:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
1:39:44 PM:                                  Dload  Upload   Total   Spent    Left  Speed
1:39:44 PM:   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
1:39:44 PM: 100    85  100    85    0     0   1666      0 --:--:-- --:--:-- --:--:--  1666
1:39:44 PM: 100    99  100    99    0     0   1253      0 --:--:-- --:--:-- --:--:--  1253
1:39:44 PM: 100   630  100   630    0     0   5943      0 --:--:-- --:--:-- --:--:--  5943
1:39:44 PM: 100   832  100   832    0     0   7111      0 --:--:-- --:--:-- --:--:--  7111
1:39:44 PM: > Verifying integrity...
1:39:44 PM: gpg: Signature made Fri 02 Oct 2020 11:17:27 AM UTC
1:39:44 PM: gpg:                using RSA key 6D98490C6F1ACDDD448E45954F77679369475BAA
1:39:44 PM: gpg: Good signature from "Yarn Packaging <yarn@dan.cx>" [unknown]
1:39:44 PM: gpg: WARNING: This key is not certified with a trusted signature!
1:39:44 PM: gpg:          There is no indication that the signature belongs to the owner.
1:39:44 PM: Primary key fingerprint: 72EC F46A 56B4 AD39 C907  BBB7 1646 B01B 86E5 0310
1:39:44 PM:      Subkey fingerprint: 6D98 490C 6F1A CDDD 448E  4595 4F77 6793 6947 5BAA
1:39:44 PM: > GPG signature looks good
1:39:44 PM: > Extracting to ~/.yarn...
1:39:44 PM: > Adding to $PATH...
1:39:44 PM: > Successfully installed Yarn 1.22.10! Please open another terminal where the `yarn` command will now be available.
1:39:45 PM: No yarn workspaces detected
1:39:45 PM: Started restoring cached node modules
1:39:45 PM: Finished restoring cached node modules
1:39:45 PM: Installing NPM modules using Yarn version 1.22.10
1:39:45 PM: yarn install v1.22.10
1:39:46 PM: warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
1:39:46 PM: [1/4] Resolving packages...
1:39:47 PM: warning packages > express > connect@2.12.0: connect 2.x series is deprecated
1:39:47 PM: warning packages > express > mkdirp@0.3.5: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
1:39:47 PM: [2/4] Fetching packages...
1:39:47 PM: warning mini-css-extract-plugin@0.4.3: Invalid bin field for "mini-css-extract-plugin".
1:40:04 PM: info fsevents@2.1.2: The platform "linux" is incompatible with this module.
1:40:04 PM: info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
1:40:04 PM: info fsevents@1.2.12: The platform "linux" is incompatible with this module.
1:40:04 PM: info "fsevents@1.2.12" is an optional dependency and failed compatibility check. Excluding it from installation.
1:40:04 PM: [3/4] Linking dependencies...
1:40:04 PM: warning "@zeit/next-sass > sass-loader@6.0.6" has unmet peer dependency "webpack@^2.0.0 || >= 3.0.0-rc.0 || ^3.0.0".
1:40:04 PM: warning "@zeit/next-sass > @zeit/next-css > css-loader@1.0.0" has unmet peer dependency "webpack@^4.0.0".
1:40:04 PM: warning "@zeit/next-sass > @zeit/next-css > mini-css-extract-plugin@0.4.3" has unmet peer dependency "webpack@^4.4.0".
1:40:04 PM: warning " > url-loader@4.0.0" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
1:40:10 PM: [4/4] Building fresh packages...
1:42:53 PM: success Saved lockfile.
1:42:53 PM: Done in 187.90s.
1:42:53 PM: NPM modules installed using Yarn
1:42:54 PM: Started restoring cached go cache
1:42:54 PM: Finished restoring cached go cache
1:42:54 PM: go version go1.16.5 linux/amd64
1:42:54 PM: go version go1.16.5 linux/amd64
1:42:54 PM: Installing missing commands
1:42:54 PM: Verify run directory
1:42:55 PM: ​
1:42:55 PM: ────────────────────────────────────────────────────────────────
1:42:55 PM:   Netlify Build                                                 
1:42:55 PM: ────────────────────────────────────────────────────────────────
1:42:55 PM: ​
1:42:55 PM: ❯ Version
1:42:55 PM:   @netlify/build 18.21.3
1:42:55 PM: ​
1:42:55 PM: ❯ Flags
1:42:55 PM:   baseRelDir: true
1:42:55 PM:   buildId: 61839c4497b7e2a801fa3a01
1:42:55 PM:   deployId: 61839c4497b7e2a801fa3a03
1:42:55 PM: ​
1:42:55 PM: ❯ Current directory
1:42:55 PM:   /opt/build/repo
1:42:55 PM: ​
1:42:55 PM: ❯ Config file
1:42:55 PM:   No config file was defined: using default values.
1:42:55 PM: ​
1:42:55 PM: ❯ Context
1:42:55 PM:   production
1:42:55 PM: ​
1:42:55 PM: ❯ Installing plugins
1:42:55 PM:    - @netlify/plugin-nextjs@1.1.5
1:43:07 PM: ​
1:43:07 PM: ❯ Loading plugins
1:43:07 PM:    - @netlify/plugin-nextjs@1.1.5 from Netlify app
1:43:07 PM: ​
1:43:07 PM: ❯ Outdated plugins
1:43:07 PM:    - @netlify/plugin-nextjs@1.1.5: latest version is 3.9.2
1:43:07 PM:      To upgrade this plugin, please uninstall and re-install it from the Netlify plugins directory (https://app.netlify.com/plugins)
1:43:07 PM: ​
1:43:07 PM: ────────────────────────────────────────────────────────────────
1:43:07 PM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
1:43:07 PM: ────────────────────────────────────────────────────────────────
1:43:07 PM: ​
1:43:07 PM: ​
1:43:07 PM: ────────────────────────────────────────────────────────────────
1:43:07 PM:   Plugin "@netlify/plugin-nextjs" failed                        
1:43:07 PM: ────────────────────────────────────────────────────────────────
1:43:07 PM: ​
1:43:07 PM:   Error message
1:43:07 PM:   Error: Please upgrade to Next.js 9.5.3 or later
1:43:07 PM: ​
1:43:07 PM:   Plugin details
1:43:07 PM:   Package:        @netlify/plugin-nextjs
1:43:07 PM:   Version:        1.1.5
1:43:07 PM:   Repository:     git+https://github.com/netlify/netlify-plugin-nextjs.git
1:43:07 PM:   npm link:       https://www.npmjs.com/package/@netlify/plugin-nextjs
1:43:07 PM:   Report issues:  https://github.com/netlify/netlify-plugin-nextjs/issues
1:43:07 PM: ​
1:43:07 PM:   Error location
1:43:07 PM:   In "onPreBuild" event in "@netlify/plugin-nextjs" from Netlify app
1:43:07 PM:       at validateNextUsage (/.netlify/plugins/node_modules/@netlify/plugin-nextjs/helpers/validateNextUsage.js:18:12)
1:43:07 PM:       at onPreBuild (/.netlify/plugins/node_modules/@netlify/plugin-nextjs/index.js:20:5)
1:43:07 PM: ​
1:43:07 PM:   Resolved config
1:43:07 PM:   build:
1:43:07 PM:     command: npm run build
1:43:07 PM:     commandOrigin: ui
1:43:07 PM:     environment:
1:43:07 PM:       - NODE_VERSION
1:43:07 PM:     publish: /opt/build/repo/public
1:43:07 PM:     publishOrigin: ui
1:43:07 PM:   plugins:
1:43:07 PM:     - inputs: {}
1:43:07 PM:       origin: ui
1:43:07 PM:       package: '@netlify/plugin-nextjs'
1:43:08 PM: Caching artifacts
1:43:08 PM: Started saving node modules
1:43:08 PM: Finished saving node modules
1:43:08 PM: Started saving build plugins
1:43:08 PM: Finished saving build plugins
1:43:08 PM: Started saving yarn cache
1:43:11 PM: Finished saving yarn cache
1:43:11 PM: Started saving pip cache
1:43:11 PM: Finished saving pip cache
1:43:11 PM: Started saving emacs cask dependencies
1:43:11 PM: Finished saving emacs cask dependencies
1:43:11 PM: Started saving maven dependencies
1:43:11 PM: Finished saving maven dependencies
1:43:11 PM: Started saving boot dependencies
1:43:11 PM: Finished saving boot dependencies
1:43:11 PM: Started saving rust rustup cache
1:43:11 PM: Finished saving rust rustup cache
1:43:11 PM: Started saving go dependencies
1:43:11 PM: Finished saving go dependencies
1:43:14 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:43:14 PM: Creating deploy upload records
1:43:14 PM: Failing build: Failed to build site
1:43:14 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
1:43:14 PM: Finished processing build request in 3m39.985183527s

even though the Essential NextJS plugin is there it still gives that error

Hi @YasirRWebDesigner

To the best of my knowledge, the @netlify/plugin-nextjs is for use with Next.js only and not compatible with React.

Try removing the plugin from your build. If you have any further issue, can you share make your repository public so others can test.

the plugin is installed automatically.

Edit: Next is one of the dependences in the package.json file.

You’d need to remove it unless you’re using Nextjs.

Yes, I removed it the build was completed but nothing is showing up.

Hi @YasirRWebDesigner,

I’m confused, are you using Nextjs or not?Your build command is next build, so it makes me think you’re using it after all?

Update about the repo: Sorry I had 4 different versions on my system and I removed the original once aswell from GitHub I upload a backup of it. The repo is still public

It wasn’t built by me I downloaded a template from Envato elements, when I did npm run build it gave a few errors but I got them fix my downgrading my node version to 14.18.1 using nvm. I am using the same version of netlify as well NODE_VERISON here’s a screenshot of the same template on my laptop

This is the template Zimed - React Next App Landing Page Template, Web Templates - Envato Elements

someome made a commit but I accidentally removed that repo

[build]
  command = "yarn build" # the command you run to build this file
  functions = "built-lambda" # netlify-lambda builds to this folder AND Netlify reads functions from here
  publish = "build" # create-react-app builds to this folder, Netlify should serve all these files statically

but it was giving an error the build dir is not present so I made a build dir in the root dir but still the same error so I made some changes into this commit the build/deploy goes without any error but it gives 404

[build]
  command = "yarn build" # the command you run to build this file
  functions = "built-lambda" # netlify-lambda builds to this folder AND Netlify reads functions from here
  publish = "public" # create-react-app builds to this folder, Netlify should serve all these files statically

Do you have a repo we can check?

yes the same url is public https://github.com/YasirRWebDesigner/hady-mat

I tried the repo and it doesn’t seem like it’s going to work very easily.

The reason is, that template is using ancient Nextjs 9 which our plugin doesn’t even support. You need to migrate the project to either Nextjs 10 or above.

If you don’t wish to use the plugin, you can uninstall it and the build works, but your website won’t load any content as it’s not a traditional static website.

Yes, it is doing exactly the same, it is building fine but the website doesn’t load. how can I upgrade the nextjs version? Do I have to make some changes or a lot?

You can simply change the version in package.json, but version 9 to version 10 would be a major version change and thus, it would include breaking changes. You might have to rewrite some parts of the app.