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

**URL:** <https://answers.netlify.com/t/plugin-netlify-plugin-nextjs-failed-on-react-project/119840>\
**Category:** Support\
**Tags:** deployment\
**Created:** [June 5, 2024, 8:06pm UTC](https://answers.netlify.com/t/plugin-netlify-plugin-nextjs-failed-on-react-project/119840 "2024-06-05T20:06:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![znkbnk](https://avatars.discourse-cdn.com/v4/letter/z/5e9695/32.png) [@znkbnk](https://answers.netlify.com/u/znkbnk)\
**Post date:** [June 5, 2024, 8:06pm UTC](https://answers.netlify.com/t/plugin-netlify-plugin-nextjs-failed-on-react-project/119840/1 "2024-06-05T20:06:41Z")

</div>

Good evening. I have a React project ( ([https://404projectschool.netlify.app/](https://404projectschool.netlify.app/)) ) and when i try to deploy it on [netlify.com](http://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](https://app.netlify.com/plugins))  
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](https://www.npmjs.com/package/@netlify/plugin-nextjs)  
8:56:22 PM: Report issues: [Issues · netlify/next-runtime · GitHub](https://github.com/netlify/next-runtime/issues)  
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](https://ntl.fyi/exit-code-2))  
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”

---

<div class="post-metadata">

**Author:** ![nathanmartin](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/nathanmartin/32/30845_2.png) [@nathanmartin](https://answers.netlify.com/u/nathanmartin)\
**Post date:** [June 5, 2024, 9:33pm UTC](https://answers.netlify.com/t/plugin-netlify-plugin-nextjs-failed-on-react-project/119840/2 "2024-06-05T21:33:24Z")

</div>

@znkbnk The relevant pieces are:

```plaintext
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:

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

```

which comes from:

```plaintext
[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`)

---

<div class="post-metadata">

**Author:** ![znkbnk](https://avatars.discourse-cdn.com/v4/letter/z/5e9695/32.png) [@znkbnk](https://answers.netlify.com/u/znkbnk)\
**Post date:** [June 5, 2024, 9:45pm UTC](https://answers.netlify.com/t/plugin-netlify-plugin-nextjs-failed-on-react-project/119840/3 "2024-06-05T21:45:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nathanmartin](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/nathanmartin/32/30845_2.png) [@nathanmartin](https://answers.netlify.com/u/nathanmartin)\
**Post date:** [June 5, 2024, 9:53pm UTC](https://answers.netlify.com/t/plugin-netlify-plugin-nextjs-failed-on-react-project/119840/4 "2024-06-05T21:53:09Z")

</div>

@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`

---

<div class="post-metadata">

**Author:** ![znkbnk](https://avatars.discourse-cdn.com/v4/letter/z/5e9695/32.png) [@znkbnk](https://answers.netlify.com/u/znkbnk)\
**Post date:** [June 5, 2024, 10:06pm UTC](https://answers.netlify.com/t/plugin-netlify-plugin-nextjs-failed-on-react-project/119840/5 "2024-06-05T22:06:42Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![nathanmartin](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/nathanmartin/32/30845_2.png) [@nathanmartin](https://answers.netlify.com/u/nathanmartin)\
**Post date:** [June 5, 2024, 10:08pm UTC](https://answers.netlify.com/t/plugin-netlify-plugin-nextjs-failed-on-react-project/119840/6 "2024-06-05T22:08:25Z")

</div>

> [@znkbnk](#):
>
> Trust me, I deleted everything related to next and plugin-nextjs

So you did originally have them in the project?

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

---

<div class="post-metadata">

**Author:** ![znkbnk](https://avatars.discourse-cdn.com/v4/letter/z/5e9695/32.png) [@znkbnk](https://answers.netlify.com/u/znkbnk)\
**Post date:** [June 5, 2024, 10:23pm UTC](https://answers.netlify.com/t/plugin-netlify-plugin-nextjs-failed-on-react-project/119840/7 "2024-06-05T22:23:23Z")

</div>

Yes I did.

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

Cant post it here as it too long.

---

<div class="post-metadata">

**Author:** ![nathanmartin](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/nathanmartin/32/30845_2.png) [@nathanmartin](https://answers.netlify.com/u/nathanmartin)\
**Post date:** [June 5, 2024, 10:27pm UTC](https://answers.netlify.com/t/plugin-netlify-plugin-nextjs-failed-on-react-project/119840/8 "2024-06-05T22:27:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![znkbnk](https://avatars.discourse-cdn.com/v4/letter/z/5e9695/32.png) [@znkbnk](https://answers.netlify.com/u/znkbnk)\
**Post date:** [June 5, 2024, 10:31pm UTC](https://answers.netlify.com/t/plugin-netlify-plugin-nextjs-failed-on-react-project/119840/9 "2024-06-05T22:31:37Z")

</div>

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

Thank You for Your time!

---

<div class="post-metadata">

**Author:** ![nathanmartin](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/nathanmartin/32/30845_2.png) [@nathanmartin](https://answers.netlify.com/u/nathanmartin)\
**Post date:** [June 5, 2024, 10:35pm UTC](https://answers.netlify.com/t/plugin-netlify-plugin-nextjs-failed-on-react-project/119840/10 "2024-06-05T22:35:19Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![znkbnk](https://avatars.discourse-cdn.com/v4/letter/z/5e9695/32.png) [@znkbnk](https://answers.netlify.com/u/znkbnk)\
**Post date:** [June 6, 2024, 6:19pm UTC](https://answers.netlify.com/t/plugin-netlify-plugin-nextjs-failed-on-react-project/119840/11 "2024-06-06T18:19:26Z")

</div>

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

Thanks for idea!
