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

out/index.html already exists #349

Closed
matt-antone opened this issue May 25, 2021 · 11 comments
Closed

out/index.html already exists #349

matt-antone opened this issue May 25, 2021 · 11 comments
Labels
priority: low status: needs reproduction this issue needs to provide a repo that reproduces the bug described type: bug code to address defects in shipped code

Comments

@matt-antone
Copy link

When running a Netlify CLI build locally or building at Netlify I get the same error. The NextJS build goes fine but the plugin stops on copying files to "out".

To Reproduce
Steps to reproduce the behavior locally:

  1. In terminal netlify build

Steps to reproduce the behavior on Netlify:

  1. Create a new site using https://github.com/matt-antone/navalign-next-js

Expected behavior
A complete build and deployment on Netlify

Versions

  • Next.js: "next": "^10.2.0",
  • plugin (if installed at fixed version): "@netlify/plugin-nextjs@^3.3.1":

If you're using the CLI to build

  • OS: [e.g. macOS, Windows] macOS
  • netlify/cli version: netlify-cli/3.30.7 darwin-x64 node-v14.16.0

If you're using file-based installation
netlify.toml:
[build]
command = "yarn build"
publish = "out"
functions = "functions"

[[plugins]]
package = "netlify-plugin-cache-nextjs"
# These options will cache the build directory at ${NETLIFY_BASE}/frontend/.next-build
[plugins.inputs]
# The path to the build directory
build_dir_path = "frontend"
# Custom build directory if you aren't using .next (https://nextjs.org/docs/api-reference/next.config.js/setting-a-custom-build-directory)
# custom_build_dir_name = ".next"

[context.production.environment]
NEXT_SERVERLESS = "true"
NODE_ENV = "production"

Output from local build:

────────────────────────────────────────────────────────────────
Netlify Build
────────────────────────────────────────────────────────────────

❯ Version
@netlify/build 11.18.1

❯ Flags
{}

❯ Current directory
/Users/antone/Dropbox (Personal)/DevProjects/Glyphix/navalign3.0

❯ Config file
/Users/antone/Dropbox (Personal)/DevProjects/Glyphix/navalign3.0/netlify.toml

❯ Context
production

❯ Loading plugins

  • @netlify/plugin-nextjs@3.3.1 from Netlify app and package.json
  • netlify-plugin-cache-nextjs@1.4.0 from netlify.toml

────────────────────────────────────────────────────────────────

  1. onPreBuild command from @netlify/plugin-nextjs
    ────────────────────────────────────────────────────────────────

info - Loaded env from /Users/antone/Dropbox (Personal)/DevProjects/Glyphix/navalign3.0/.env.local
info - Using webpack 5. Reason: future.webpack5 option enabled https://nextjs.org/docs/messages/webpack5
Image domains set in next.config.js are ignored.
Please set the env variable NEXT_IMAGE_ALLOWED_DOMAINS to "res.cloudinary.com" instead
No Next.js cache to restore.

(@netlify/plugin-nextjs onPreBuild completed in 468ms)

────────────────────────────────────────────────────────────────
2. onPreBuild command from netlify-plugin-cache-nextjs
────────────────────────────────────────────────────────────────

No cache found for the .next folder at the location frontend/.next/cache

(netlify-plugin-cache-nextjs onPreBuild completed in 123ms)

────────────────────────────────────────────────────────────────
3. build.command from netlify.toml
────────────────────────────────────────────────────────────────

$ yarn build
yarn run v1.22.10
$ next build
info - Using webpack 5. Reason: future.webpack5 option enabled https://nextjs.org/docs/messages/webpack5
info - Checking validity of types
info - Creating an optimized production build
info - Compiled successfully
info - Collecting page data
[=== ] info - Generating static pages (0/291)[react-markdown] Warning: please pass a string as children (not: In addition to the equity market declines, what stands out about 2018 is the breadth of negative returns across almost every type of asset class and financial market, whether bonds, equities, or commodities. Even core investment-grade bonds were in the red. It was extremely difficult to make money in the financial markets last year.,[object Object])
[== ] info - Generating static pages (145/291)[react-markdown] Warning: please pass a string as children (not: In addition to the equity market declines, what stands out about 2018 is the breadth of negative returns across almost every type of asset class and financial market, whether bonds, equities, or commodities. Even core investment-grade bonds were in the red. It was extremely difficult to make money in the financial markets last year.,[object Object])
info - Generating static pages (291/291)
info - Finalizing page optimization

Page Size First Load JS
┌ ● / 3.9 kB 256 kB
├ ● /[slug] 3.44 kB 255 kB
├ ├ /careers
├ ├ /disclosures
├ ├ /form-crs
├ └ [+4 more paths]
├ ○ /404 3.05 kB 68.1 kB
├ ● /services 1.47 kB 148 kB
├ ● /services/[slug] 5.67 kB 258 kB
├ ├ /services/2018-in-review-worst-year-since-great-recession
├ ├ /services/4-financial-priorities-young-families-should-address
├ ├ /services/401k-the-retirement-marathon
├ └ [+121 more paths]
├ ● /services/business/[slug] 6.67 kB 259 kB
├ ├ /services/business/401k-and-pension-plan-fiduciary
├ ├ /services/business/business-owner
├ └ /services/business/succession-exit-planning
├ ● /services/family/[slug] 6.66 kB 259 kB
├ ├ /services/family/empty-nesters
├ ├ /services/family/married-no-children
├ ├ /services/family/raising-a-family
├ └ [+2 more paths]
├ ● /services/individual/[slug] 6.67 kB 259 kB
├ ├ /services/individual/business-executive
├ ├ /services/individual/doctors-physicians
├ ├ /services/individual/entertainment-industry
├ └ [+3 more paths]
├ ● /updates 1.47 kB 148 kB
├ ● /updates/[slug] 5.67 kB 258 kB
├ ├ /updates/2018-in-review-worst-year-since-great-recession
├ ├ /updates/4-financial-priorities-young-families-should-address
├ ├ /updates/401k-the-retirement-marathon
├ └ [+121 more paths]
├ ● /what-we-do 1.38 kB 253 kB
├ ● /what-we-do/[slug] 3.48 kB 255 kB
├ ├ /what-we-do/401k-and-pension-plan-fiduciary
├ ├ /what-we-do/fiduciary-financial-planning
├ ├ /what-we-do/fiduciary-investment-services
├ └ [+2 more paths]
├ ● /who-we-are 1.65 kB 254 kB
└ ● /who-we-are/[slug] 8.48 kB 260 kB
├ /who-we-are/christopher-carter
├ /who-we-are/david-jacobs
├ /who-we-are/index
└ [+7 more paths]

  • First Load JS shared by all 65 kB
    ├ chunks/commons.b12e07.js 13.5 kB
    ├ chunks/framework.85c078.js 42.6 kB
    ├ chunks/main.d2a1b3.js 6.9 kB
    ├ chunks/pages/_app.feb5a5.js 1.03 kB
    └ chunks/webpack.14e883.js 1 kB

λ (Lambda) server-side renders at runtime (uses getInitialProps or getServerSideProps)
○ (Static) automatically rendered as static HTML (uses no initial props)
● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)
(ISR) incremental static regeneration (uses revalidate in getStaticProps)

✨ Done in 12.54s.

(build.command completed in 12.7s)

────────────────────────────────────────────────────────────────
4. onBuild command from @netlify/plugin-nextjs
────────────────────────────────────────────────────────────────

** Running Next on Netlify package **
🚀 Next on Netlify 🚀
💼 Copying static NextJS assets to out

────────────────────────────────────────────────────────────────
Plugin "@netlify/plugin-nextjs" internal error
────────────────────────────────────────────────────────────────

Error message
Error: 'out/_next/static/JeCJ-lXogoq2R7bQ8v0od/_buildManifest.js' already exists

Plugin details
Package: @netlify/plugin-nextjs
Version: 3.3.1
Repository: git+https://github.com/netlify/netlify-plugin-nextjs.git
npm link: https://www.npmjs.com/package/@netlify/plugin-nextjs
Report issues: https://github.com/netlify/netlify-plugin-nextjs/issues

Error location
In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app and package.json
at mayCopyFile (/Users/antone/Dropbox (Personal)/DevProjects/Glyphix/navalign3.0/node_modules/fs-extra/lib/copy-sync/copy-sync.js:62:11)
at onFile (/Users/antone/Dropbox (Personal)/DevProjects/Glyphix/navalign3.0/node_modules/fs-extra/lib/copy-sync/copy-sync.js:54:10)
at getStats (/Users/antone/Dropbox (Personal)/DevProjects/Glyphix/navalign3.0/node_modules/fs-extra/lib/copy-sync/copy-sync.js:48:44)
at startCopy (/Users/antone/Dropbox (Personal)/DevProjects/Glyphix/navalign3.0/node_modules/fs-extra/lib/copy-sync/copy-sync.js:38:10)
at copyDirItem (/Users/antone/Dropbox (Personal)/DevProjects/Glyphix/navalign3.0/node_modules/fs-extra/lib/copy-sync/copy-sync.js:122:10)
at /Users/antone/Dropbox (Personal)/DevProjects/Glyphix/navalign3.0/node_modules/fs-extra/lib/copy-sync/copy-sync.js:115:39
at Array.forEach ()
at copyDir (/Users/antone/Dropbox (Personal)/DevProjects/Glyphix/navalign3.0/node_modules/fs-extra/lib/copy-sync/copy-sync.js:115:23)
at onDir (/Users/antone/Dropbox (Personal)/DevProjects/Glyphix/navalign3.0/node_modules/fs-extra/lib/copy-sync/copy-sync.js:105:10)
at getStats (/Users/antone/Dropbox (Personal)/DevProjects/Glyphix/navalign3.0/node_modules/fs-extra/lib/copy-sync/copy-sync.js:45:37)

Resolved config
build:
command: yarn build
commandOrigin: config
environment:
- NEXT_SERVERLESS
- NODE_ENV
publish: /Users/antone/Dropbox (Personal)/DevProjects/Glyphix/navalign3.0/out
functionsDirectory: /Users/antone/Dropbox (Personal)/DevProjects/Glyphix/navalign3.0/functions
plugins:
- inputs: {}
origin: ui
package: '@netlify/plugin-nextjs'
- inputs: {}
origin: config
package: netlify-plugin-cache-nextjs

@lindsaylevine
Copy link

@matt-antone hey matt! check out the CLI build part of our README: https://github.com/netlify/netlify-plugin-nextjs#cli-usage

unfortunately right now the CLI experience is still a bit fidgety as described in the README. we're getting a lot closer to cleaning up CLI builds under the hood to make this experience a lot easier (for plugin devs and plugin users)!

the reason you might be seeing your error in particular is if your node_modules changed/purged between builds. the best way to handle that in this case is to just delete out and rebuild. i looked at your repo and don't see anything preexisting in out that you would want to keep (from deleting between builds, when you see this error).

let me know if this solves your issue!

@lindsaylevine lindsaylevine added priority: low type: bug code to address defects in shipped code labels May 26, 2021
@tmilewski
Copy link

tmilewski commented Jun 1, 2021

@lindsaylevine I'm seeing a similar issue, but it's not working on the Netlify build process. Plot twist though, it works locally using the CLI.

I'm not sure how to debug at the moment seeing as I can't see the interim output on Netlify.

EDIT: I've also made sure to clear cache, to no avail.

@lindsaylevine
Copy link

@tmilewski hmmm, how strange! what is the exact error you're seeing? regardless of that answer, though, i'll probably need a repo that reproduces your issue to figure out what's going on exactly 🙏

@tmilewski
Copy link

I'm on my phone currently, so I'll try and provide more later, but I'm running an NX monorepo with two front-end NextJS applications. At first, I was running into an error around .next/static not having files. I fixed that by manually setting the Next configuration distDir with an ENV variable to dist/apps/[app name]/.static/. That's where I then wound up where it's complaining that a chunk already exists in _next/.

@matt-antone
Copy link
Author

@matt-antone hey matt! check out the CLI build part of our README: https://github.com/netlify/netlify-plugin-nextjs#cli-usage

unfortunately right now the CLI experience is still a bit fidgety as described in the README. we're getting a lot closer to cleaning up CLI builds under the hood to make this experience a lot easier (for plugin devs and plugin users)!

the reason you might be seeing your error in particular is if your node_modules changed/purged between builds. the best way to handle that in this case is to just delete out and rebuild. i looked at your repo and don't see anything preexisting in out that you would want to keep (from deleting between builds, when you see this error).

let me know if this solves your issue!

Hi Lindsay,

Just picking this up again. I went so far as to rebuild using the next-netlify-starter. Deloying worked locally all day yesterday without having to delete any folders. Woke up this morning and ran the build in the same terminal with no changes made for giggles. And it started throwing errors again.

I've updated manually to 3.4.1 and am still having the same issue in both local and netlify builds. Just deleting the /out folder doesn't work for me locally.

Link to the latest deploy log:
https://app.netlify.com/sites/loving-shaw-92ea86/deploys/60ba761c5261020008cbb365#L5-L10

@sangsta
Copy link

sangsta commented Jun 7, 2021

I'm hitting the same issue. I recently converted a react codebase to next js and installed the plugin via the manual installation directions in the README. Using "@netlify/plugin-nextjs": "^3.4.2".

Fails on netlify, but yarn build works fine locally.

12:25:59 AM: ────────────────────────────────────────────────────────────────
12:25:59 AM:   3. onBuild command from @netlify/plugin-nextjs                
12:25:59 AM: ────────────────────────────────────────────────────────────────
12:25:59 AM: ​
12:25:59 AM: ** Running Next on Netlify package **
12:25:59 AM: 🚀 Next on Netlify 🚀
12:25:59 AM: 🌍️ Copying public/ folder to out
12:26:00 AM: 💼 Copying static NextJS assets to out
12:26:00 AM: 💫 Setting up API endpoints as Netlify Functions in netlify/functions
12:26:00 AM: 💫 Setting up pages with getInitialProps as Netlify Functions in netlify/functions
12:26:00 AM: 💫 Setting up pages with getServerSideProps as Netlify Functions in netlify/functions
12:26:00 AM: 🔥 Copying pre-rendered pages with getStaticProps and JSON data to out
12:26:00 AM: 💫 Setting up pages with getStaticProps and fallback: true as Netlify Functions in netlify/functions
12:26:00 AM: 💫 Setting up pages with getStaticProps and revalidation interval as Netlify Functions in netlify/functions
12:26:00 AM: 🔥 Copying pre-rendered pages without props to out
12:26:00 AM: Building 22 pages
12:26:00 AM: 💼 Copying WP4 dynamic import chunks to netlify/functions/next_prayers/nextPage
12:26:00 AM: 💼 Copying WP4 dynamic import chunks to netlify/functions/next_prayers_id/nextPage
12:26:00 AM: ​
12:26:00 AM: ────────────────────────────────────────────────────────────────
12:26:00 AM:   Plugin "@netlify/plugin-nextjs" internal error                
12:26:00 AM: ────────────────────────────────────────────────────────────────
12:26:00 AM: ​
12:26:00 AM:   Error message
12:26:00 AM:   Error: 'out/index.html' already exists
12:26:00 AM: ​
12:26:00 AM:   Plugin details
12:26:00 AM:   Package:        @netlify/plugin-nextjs
12:26:00 AM:   Version:        3.4.2
12:26:00 AM:   Repository:     git+https://github.com/netlify/netlify-plugin-nextjs.git
12:26:00 AM:   npm link:       https://www.npmjs.com/package/@netlify/plugin-nextjs
12:26:00 AM:   Report issues:  https://github.com/netlify/netlify-plugin-nextjs/issues
12:26:00 AM: ​
12:26:00 AM:   Error location
12:26:00 AM:   In "onBuild" event in "@netlify/plugin-nextjs" from netlify.toml and package.json
12:26:00 AM:       at mayCopyFile (/opt/build/repo/node_modules/fs-extra/lib/copy-sync/copy-sync.js:62:11)
12:26:00 AM:       at onFile (/opt/build/repo/node_modules/fs-extra/lib/copy-sync/copy-sync.js:54:10)
12:26:00 AM:       at getStats (/opt/build/repo/node_modules/fs-extra/lib/copy-sync/copy-sync.js:48:44)
12:26:00 AM:       at startCopy (/opt/build/repo/node_modules/fs-extra/lib/copy-sync/copy-sync.js:38:10)
12:26:00 AM:       at handleFilterAndCopy (/opt/build/repo/node_modules/fs-extra/lib/copy-sync/copy-sync.js:33:10)
12:26:00 AM:       at copySync (/opt/build/repo/node_modules/fs-extra/lib/copy-sync/copy-sync.js:26:10)
12:26:00 AM:       at setupStaticFileForPage (/opt/build/repo/node_modules/@netlify/plugin-nextjs/src/lib/helpers/setupStaticFileForPage.js:12:3)
12:26:00 AM: ​
12:26:00 AM:   Resolved config
12:26:00 AM:   build:
12:26:00 AM:     command: yarn build
12:26:00 AM:     commandOrigin: config
12:26:00 AM:     publish: /opt/build/repo/out
12:26:00 AM:   functions:
12:26:00 AM:     '*': {}
12:26:00 AM:   plugins:
12:26:00 AM:     - inputs: {}
12:26:00 AM:       origin: config
12:26:00 AM:       package: '@netlify/plugin-nextjs'
12:26:00 AM: Caching artifacts
12:26:00 AM: Started saving node modules
12:26:00 AM: Finished saving node modules
12:26:00 AM: Started saving build plugins
12:26:00 AM: Finished saving build plugins
12:26:00 AM: Started saving yarn cache
12:26:00 AM: Finished saving yarn cache
12:26:00 AM: Started saving pip cache
12:26:00 AM: Finished saving pip cache
12:26:00 AM: Started saving emacs cask dependencies
12:26:00 AM: Finished saving emacs cask dependencies
12:26:00 AM: Started saving maven dependencies
12:26:00 AM: Finished saving maven dependencies
12:26:00 AM: Started saving boot dependencies
12:26:00 AM: Finished saving boot dependencies
12:26:00 AM: Started saving rust rustup cache
12:26:00 AM: Finished saving rust rustup cache
12:26:00 AM: Started saving go dependencies
12:26:00 AM: Finished saving go dependencies
12:26:04 AM: Build failed due to a plugin error: Build script returned non-zero exit code: 3
12:26:04 AM: Creating deploy upload records
12:26:04 AM: Failing build: Failed to build site
12:26:04 AM: Failed during stage 'building site': Build script returned non-zero exit code: 3
12:26:04 AM: Finished processing build request in 1m23.358990405s

@lindsaylevine
Copy link

@sangsta are you able to provide a simple repo that reproduces this issue? i tried @matt-antone's navalign repo in the original post and it errors out in a bunch of other ways. i'm unable to reproduce this on my own :/

@lindsaylevine lindsaylevine added the status: needs reproduction this issue needs to provide a repo that reproduces the bug described label Jun 10, 2021
@lindsaylevine
Copy link

closing since we haven't received a response/repro. please re-comment if you continue to need help!

@tmilewski
Copy link

tmilewski commented Jun 29, 2021

@lindsaylevine While not ideal, (see: losing caching, etc) what I wound up doing to make this workable in my Nx monorepo is creating a plugin and placing it before @netlify/plugin-nextjs:

const { copySync } = require('fs-extra');

module.exports = {
  onBuild: async () => {
    const currentProject = process.env.PROJECT_NAME;

    if (currentProject) {
      copySync(
        `/opt/build/repo/dist/apps/${currentProject}/`,
        '/opt/build/repo',
        { overwrite: true }
      );
    }
  },
};
[[plugins]]
  package = "./tools/plugins/netlify/stop-build"

[[plugins]]
  package = "netlify-plugin-contextual-env"

[[plugins]]
  package = "./tools/plugins/netlify/nx-nextjs"

[[plugins]]
  package = "@netlify/plugin-nextjs"

@lindsaylevine
Copy link

@tmilewski take a look at #433! this will go out in our next release :)

@michael-goss
Copy link

I've had the same issue. Actually the error message perfectly described the problem. In my project I've migrated from CRA to Nextjs and there was still an index.html in the public/ folder which is being copied to out/.
After deleting the obsolete index.html from my public/ folder it all worked fine. duh

serhalp pushed a commit that referenced this issue Apr 5, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
* feat: upload static export to cdn

* feat: ensure out directory

* fix: check standalone only in standalone mode

* test: add export fixture

* test: ignore out dir in test fixtures

* test: add e2e test for output export

* fix: check for undefined output config

* fix: check properly for undefined output config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low status: needs reproduction this issue needs to provide a repo that reproduces the bug described type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

5 participants