Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear publish directory before building #464

Closed
ascorbic opened this issue Jun 30, 2021 · 9 comments
Closed

Clear publish directory before building #464

ascorbic opened this issue Jun 30, 2021 · 9 comments

Comments

@ascorbic
Copy link
Contributor

Currently if out exists from a previous build, the build will fail as it refuses to overwrite the old assets. The build should clear the contents of the publish dir so that builds can happen. It needs to ensure that it hasn't accidentally been set to the root of the repo too.

@lindsaylevine
Copy link

is this for the CLI? this is what https://github.com/netlify/netlify-plugin-nextjs/blob/main/src/lib/helpers/handleFileTracking.js is supposed to take care of

@kandizzy
Copy link

kandizzy commented Jul 21, 2021

Update:
This problem occurred because I had an index.tsx in /pages and an index.html in /public

I am experiencing this issue. I cannot get my site to deploy. I had no problem deploying the starter app which I cloned. I found another post to the forums with the same issue. The differences I have noted between the starter app and mine are

  • starter app is deployed with @netlify/build 16.0.0. My app is deploying with @netlify/build 16.1.0
  • starter app is using Next.js 11.0.0, my app is using Next.js 11.0.1

The deploy logs are identical until it tries to copy files into the build directory out. Then it errors out even if it is the first time I try a deploy (I created a few new sites to be sure). Any suggestions on how to get around this would be much appreciated!

This happens both in the Netlify UI and when using the Netlify CLI. Interestly, netlify dev -live works.

10:20:53 AM: ────────────────────────────────────────────────────────────────
10:20:53 AM:   3. onBuild command from @netlify/plugin-nextjs                
10:20:53 AM: ────────────────────────────────────────────────────────────────
10:20:53 AM: ​
10:20:53 AM: Detected Next.js site. Copying files...
10:20:53 AM: ** Running Next on Netlify package **
10:20:53 AM: 🚀 Next on Netlify 🚀
10:20:53 AM: 🌍️ Copying public folder to /opt/build/repo/out
10:20:53 AM: 💼 Copying static NextJS assets to /opt/build/repo/out
10:20:53 AM: 💫 Setting up API endpoints as Netlify Functions in /opt/build/repo/netlify/functions
10:20:53 AM: 💫 Setting up pages with getInitialProps as Netlify Functions in /opt/build/repo/netlify/functions
10:20:53 AM: 💫 Setting up pages with getServerSideProps as Netlify Functions in /opt/build/repo/netlify/functions
10:20:53 AM: 🔥 Copying pre-rendered pages with getStaticProps and JSON data to /opt/build/repo/out
10:20:53 AM: 💫 Setting up pages with getStaticProps and fallback: true as Netlify Functions in /opt/build/repo/netlify/functions
10:20:53 AM: 💫 Setting up pages with getStaticProps and revalidation interval as Netlify Functions in /opt/build/repo/netlify/functions
10:20:53 AM: 🔥 Copying pre-rendered pages without props to /opt/build/repo/out
10:20:53 AM: Building 4 pages
10:20:53 AM: 
10:20:53 AM: ────────────────────────────────────────────────────────────────
10:20:53 AM:   Plugin "@netlify/plugin-nextjs" internal error                
10:20:53 AM: ────────────────────────────────────────────────────────────────
10:20:53 AM: ​
10:20:53 AM:   Error message
10:20:53 AM:   Error: '/opt/build/repo/out/index.html' already exists
10:20:53 AM: ​
10:20:53 AM:   Plugin details
10:20:53 AM:   Package:        @netlify/plugin-nextjs
10:20:53 AM:   Version:        3.7.1
10:20:53 AM:   Repository:     git+https://github.com/netlify/netlify-plugin-nextjs.git
10:20:53 AM:   npm link:       https://www.npmjs.com/package/@netlify/plugin-nextjs
10:20:53 AM:   Report issues:  https://github.com/netlify/netlify-plugin-nextjs/issues
10:20:53 AM: ​
10:20:53 AM:   Error location
10:20:53 AM:   In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app
10:20:53 AM:       at mayCopyFile (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/copy-sync/copy-sync.js:62:11)
10:20:53 AM:       at onFile (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/copy-sync/copy-sync.js:54:10)
10:20:53 AM:       at getStats (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/copy-sync/copy-sync.js:48:44)
10:20:53 AM:       at startCopy (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/copy-sync/copy-sync.js:38:10)
10:20:53 AM:       at handleFilterAndCopy (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/copy-sync/copy-sync.js:33:10)
10:20:53 AM:       at copySync (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/copy-sync/copy-sync.js:26:10)
10:20:53 AM:       at setupStaticFileForPage (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/src/lib/helpers/setupStaticFileForPage.js:12:3)
10:20:53 AM: ​
10:20:53 AM:   Resolved config
10:20:53 AM:   build:
10:20:53 AM:     command: yarn build
10:20:53 AM:     commandOrigin: config
10:20:53 AM:     publish: /opt/build/repo/out
10:20:53 AM:     publishOrigin: config
10:20:53 AM:   plugins:
10:20:53 AM:     - inputs: {}
10:20:53 AM:       origin: ui
10:20:53 AM:       package: '@netlify/plugin-nextjs'

@lindsaylevine
Copy link

@kandizzy hey! i forked the starter repo, upgraded to next 11.0.1 and used the noted build version, and i was able to deploy. you can see logs https://app.netlify.com/sites/happy-yalow-f6a8f1/deploys/60f9688891797ee107262897. i believe you may already have an index.html in your publish folder but not entirely sure. we'd need to see your exact code, deploy settings and/or netlify.toml.

@kandizzy
Copy link

@lindsaylevine hi! yes, that's exactly what happened. I had an index.tsx in /pages and an index.html in /public

@lindsaylevine
Copy link

@kandizzy awesome, so your issue is fixed? (since you shouldnt need an index.html in your /public because of index.tsx presumedly using getStaticProps and trying to prerender into out)

@kandizzy
Copy link

@lindsaylevine yes, I am able to deploy now. I did change my build command to rm -rf out && yarn build. I am not sure that was entirely necessary though. In the meantime, I updated my original comment with this information in case anyone has a double file and runs into the same problem.

@johnclary
Copy link

johnclary commented Sep 21, 2021

hello! just want to report that i came across the same issue when migrating to next from create-react-app. CRA uses a public/index.html file as described here, and we had overlooked it when transitioning our app structure. It would seem that a local build quietly overwrites this file, however the Netlify build was failing.

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

Deleting the file fixed my issue. Thanks!

@acollierr17
Copy link

hello! just want to report that i came across the same issue when migrating to next from create-react-app. CRA uses a public/index.html file as described here, and we had overlooked it when transitioning our app structure. It would seem that a local build quietly overwrites this file, however the Netlify build was failing.

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

Deleting the file fixed my issue. Thanks!

Would also like to confirm that deleting /public/index.html fixed my issue too!

@lindsaylevine
Copy link

closing since this will not be an issue in the plugin rewrite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants