Deploy failed for error in @netlify/plugin-nextjs plugin

I tried several times but the same problem - deploy failed due to an error in @netlify/plugin-nextjs plugin.

Plugin "@netlify/plugin-nextjs" internal error

Error: '/opt/build/repo/out/index.html' already exists

In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app
at mayCopyFile (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/copy-sync/copy-sync.js:62:11)
at onFile (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/copy-sync/copy-sync.js:54:10)
at getStats (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/copy-sync/copy-sync.js:48:44)
at startCopy (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/copy-sync/copy-sync.js:38:10)
at handleFilterAndCopy (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/copy-sync/copy-sync.js:33:10)
at copySync (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/copy-sync/copy-sync.js:26:10)
at setupStaticFileForPage (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/src/lib/helpers/setupStaticFileForPage.js:12:3)

And

9:55:04 AM: Building 47 pages
9:55:05 AM: ​
9:55:05 AM: ────────────────────────────────────────────────────────────────
9:55:05 AM:   Plugin "@netlify/plugin-nextjs" internal error                
9:55:05 AM: ────────────────────────────────────────────────────────────────
9:55:05 AM: ​
9:55:05 AM:   Error message
9:55:05 AM:   Error: '/opt/build/repo/out/index.html' already exists
9:55:05 AM: ​

I will highly appreciate any help to fix so that I can deploy my first site here. :slight_smile:

Hi @rankly76

It appears there is already an out directory in your project (possibly because you have built locally and pushed to remote.) Is this correct? If so, can you remove it from the git repository you are deploying from. If not, can you share your repository?

Hi @coelmay ,
I run the build command but out folder is ignored list. I double-checked in the git repository and found no out folder.

Is there any way to share the repository privately with you?

This was a known issue in a previous version of the Next.js plugin however was addressed here.

What version of the Next.js plugin are you using?

If you are using an older version, could you upgrade the version you are using (currently v4 is in beta and v3 is still usable.) Check out the build plugin documentation for managing/upgrading/removing plugins.

Thanks. I have not installed any plugins. I am new here. The plugins are being added here when I click the deploy button here. Should I add plugins myself ?

Tried again still the same problem. I will highly appreciate any help.

────────────────────────────────────────────────────────────────
12:27:43 PM:   Plugin "@netlify/plugin-nextjs" internal error                
12:27:43 PM: ────────────────────────────────────────────────────────────────
12:27:43 PM: ​
12:27:43 PM:   Error message
12:27:43 PM:   Error: '/opt/build/repo/out/index.html' already exists

In the deploy log what version plugin is loading? e.g.

❯ Loading plugins
   - @netlify/plugin-nextjs@3.9.2 from Netlify app

Also, what version of Next.js are you using? e.g.

Using Next.js 12.0.3

(or if it doesn’t say in the log, from the package.json).

Thanks.

Plugin details
12:27:43 PM:   Package:        @netlify/plugin-nextjs
12:27:43 PM:   Version:        3.9.2
Next.js 12.0.3

As you are using the same version as my test, I’m a little lost.

What is the build command you are using (e.g. npm run build)? Are you running next export to make the site static, or is it set as serverless?

Have you looked over Next.js on Netlify | Netlify Docs to check you are using the suggested configuration?