Plugin "@netlify/plugin-nextjs" failed on React project

Good evening. I have a React project ( (https://404projectschool.netlify.app/) ) and when i try to deploy it on netlify.com i get this error:

Netlify Build
8:56:08 PM: ────────────────────────────────────────────────────────────────
8:56:08 PM: ​
8:56:08 PM: ❯ Version
8:56:08 PM: @netlify/build 29.46.5
8:56:08 PM: ​
8:56:08 PM: ❯ Flags
8:56:08 PM: baseRelDir: true
8:56:08 PM: buildId: 6660c2a46d21f100080bdca4
8:56:08 PM: deployId: 6660c2a46d21f100080bdca6
8:56:08 PM: ​
8:56:08 PM: ❯ Current directory
8:56:08 PM: /opt/build/repo
8:56:08 PM: ​
8:56:08 PM: ❯ Config file
8:56:08 PM: /opt/build/repo/netlify.toml
8:56:08 PM: ​
8:56:08 PM: ❯ Context
8:56:08 PM: production
8:56:08 PM: ​
8:56:08 PM: ❯ Using Next.js Runtime - v4.41.3
8:56:08 PM: ​
8:56:08 PM: ❯ Loading plugins
8:56:08 PM: - @netlify/plugin-lighthouse@6.0.0 from Netlify app
8:56:08 PM: ​
8:56:08 PM: ❯ Outdated plugins
8:56:08 PM: - @netlify/plugin-nextjs@4.41.3: latest version is 5.3.2
8:56:08 PM: To upgrade this plugin, please uninstall and re-install it from the Netlify plugins directory (Netlify App)
8:56:10 PM: No Next.js cache to restore.
8:56:10 PM: ​
8:56:10 PM: build.command from netlify.toml
8:56:10 PM: ──────────────────────────────────────────────────────────────────
8:56:22 PM: ​
8:56:22 PM: Error message
8:56:22 PM: Error: The directory “/opt/build/repo/build” does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
8:56:22 PM: In most cases it should be set to “.next”, unless you have chosen a custom “distDir” in your Next config.
8:56:22 PM: If you are using “next export” then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to “true”.
8:56:22 PM: ​
8:56:22 PM: Plugin details
8:56:22 PM: Package: @netlify/plugin-nextjs
8:56:22 PM: Version: 4.41.3
8:56:22 PM: Repository: git+https://github.com/netlify/next-runtime.git
8:56:22 PM: npm link: @netlify/plugin-nextjs - npm
8:56:22 PM: Report issues: Issues · netlify/next-runtime · GitHub
8:56:22 PM: ​
8:56:22 PM: Error location
8:56:22 PM: In “onBuild” event in “@netlify/plugin-nextjs” from Netlify app
8:56:22 PM: ​
8:56:22 PM: Resolved config
8:56:22 PM: build:
8:56:22 PM: command: npm run build
8:56:22 PM: commandOrigin: config
8:56:22 PM: environment:
8:56:22 PM: - REACT_APP_FIREBASE_API_KEY
8:56:22 PM: - REACT_APP_FIREBASE_AUTH_DOMAIN
8:56:22 PM: - REACT_APP_STRIPE_KEY
8:56:22 PM: - SENDGRID_API_KEY
8:56:22 PM: - SENDGRID_TEMPLATE_ID
8:56:22 PM: - NEXT_PRIVATE_TARGET
8:56:22 PM: publish: /opt/build/repo/build
8:56:22 PM: publishOrigin: config
8:56:22 PM: functionsDirectory: /opt/build/repo/netlify/functions
8:56:22 PM: plugins:
8:56:22 PM: - inputs: {}
8:56:22 PM: origin: ui
8:56:22 PM: package: ‘@netlify/plugin-nextjs’
8:56:22 PM: - inputs: {}
8:56:22 PM: origin: ui
8:56:22 PM: package: ‘@netlify/plugin-lighthouse’
8:56:22 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
8:56:23 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
8:56:23 PM: Failing build: Failed to build site
8:56:23 PM: Finished processing build request in 43.588s

my netlify.toml file is:

[build]
command = “npm run build”
publish = “build”

@znkbnk The relevant pieces are:

8:56:22 PM: Error message
8:56:22 PM: Error: The directory “/opt/build/repo/build” does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
8:56:22 PM: In most cases it should be set to “.next”, unless you have chosen a custom “distDir” in your Next config.

and:

8:56:22 PM: publish: /opt/build/repo/build

which comes from:

[build]
command = "npm run build"
publish = "build" <----- This

You have your publish directory set to build.

The error provides some help for fixing it with:
In most cases it should be set to “.next”, unless you have chosen a custom “distDir” in your Next config.

To fix you would change your publish directory from build to your actual publish directory (probably .next)

the thing is that my project made based on React not Next

@znkbnk Sorry I missed that from your thread title.

That’s pretty funny, but it doesn’t change the ultimate error, of the publish directory not being found, but it does reveal that more than one thing is wrong.

Do you have anything Next related in your package.json?

I can see the build references @netlify/plugin-nextjs

This is my package.json. Trust me, I deleted everything related to next and plugin-nextjs…

{
“name”: “projectschool”,
“version”: “0.1.0”,
“private”: true,
“dependencies”: {
“achingbrain/nat-port-mapper”: “^1.0.7”,
“fortawesome/fontawesome-free”: “^6.5.1”,
“sendgrid/mail”: “^8.1.3”,
“stripe/react-stripe-js”: “^2.6.2”,
“stripe/stripe-js”: “^3.0.10”,
“testing-library/jest-dom”: “^5.17.0”,
“testing-library/react”: “^13.4.0”,
“testing-library/user-event”: “^13.5.0”,
“ajv”: “^8.15.0”,
“bootstrap”: “^5.3.2”,
“browserslist”: “^4.23.0”,
“cors”: “^2.8.5”,
“firebase”: “^10.12.2”,
“firebase-admin”: “^12.1.1”,
“gsap”: “^3.12.5”,
“react”: “^18.3.1”,
“react-bootstrap”: “^2.10.1”,
“react-dom”: “^18.3.1”,
“react-firebase-hooks”: “^5.1.1”,
“react-google-button”: “^0.7.2”,
“react-icons”: “^5.0.1”,
“react-router-dom”: “^6.22.0”,
“react-scripts”: “^5.0.1”,
“react-toastify”: “^10.0.4”,
“web-vitals”: “^2.1.4”
},
“scripts”: {
“start”: “react-scripts start”,
“build”: “react-scripts build”,
“test”: “react-scripts test”,
“eject”: “react-scripts eject”
},
“eslintConfig”: {

"extends": [
  "react-app",
  "react-app/jest"
]

},
“browserslist”: {
“production”: [
“>0.2%”,
“not dead”,
“not op_mini all”
],
“development”: [
“last 1 chrome version”,
“last 1 firefox version”,
“last 1 safari version”
]
},
“devDependencies”: {
@babel/plugin-proposal-private-property-in-object”: “^7.21.11”,
“gh-pages”: “^6.1.1”
}
}

Thank You so much that You find time to reply friend :slight_smile:

So you did originally have them in the project?

Make sure your package-lock.json is updated and also has no references to them.

Yes I did.

package-lock.json has nothing related and no references.

Cant post it here as it too long.

If you believe something is “stuck” on Netlify’s side, you could recreate it as a new project in your account.

If everything that identifies it as a Next project has been removed you’d expect those build log notes to go away.

If they still appear you could investigate further as to why.

I was thinking about that, but I left as a last solution, thats why first i created this post.

Thank You for Your time!

@znkbnk It’s easy to do, and doesn’t require deleting the original project or waiting for assistance from anyone else, so I’d just give it a try and see what you discover.

1 Like

Indeed it was easy, I just reacreated the project, deleted the lst one and it works!

Thanks for idea!