Closed
Description
Describe the bug
I'm trying out next.js/nx/netlify combination and my build fails from the moment I add getStaticProps function to index.tsx
The error message is a bit obscure and this doesn't happen on Vercel.
Plugin "@netlify/plugin-nextjs" internal error
Error: ENOENT: no such file or directory, stat '.next/serverless/pages/index.html'
In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app
at Object.statSync (fs.js:933:3)
at Object.statSync (/opt/build/repo/.netlify/plugins/node_modules/graceful-fs/polyfills.js:311:34)
at statSync (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/util/stat.js:10:52)
at getStatsSync (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/util/stat.js:24:19)
at Object.checkPathsSync (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/util/stat.js:49:33)
at copySync (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/copy-sync/copy-sync.js:24:38)
at setupStaticFileForPage (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/src/lib/helpers/setupStaticFileForPage.js:12:3)
at async /opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/src/lib/pages/getStaticProps/setup.js:27:5
at async asyncForEach (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/src/lib/helpers/asyncForEach.js:3:5)
at async setup (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/src/lib/pages/getStaticProps/setup.js:22:3)
Error properties:
{
errno: -2,
syscall: 'stat',
code: 'ENOENT',
path: '.next/serverless/pages/index.html'
}
To Reproduce
I have setup an example repo: https://github.com/simonpeters/nx-test
commit 680acdf1
builds but 042b554e
doesn't
the only change is that the code below is added to the index.tsx
file
export function getStaticProps(context) {
const data = [];
return {
props: { data }, // will be passed to the page component as props
}
}
succesful build of 680acdf1
3:47:18 PM: Build ready to start
3:47:20 PM: build-image version: 0582042f4fc261adc7bd8333f34884959c577302
3:47:20 PM: build-image tag: v3.7.6
3:47:20 PM: buildbot version: 03c6f9d243f25556225c9548fcb276f97b8bf623
3:47:20 PM: Fetching cached dependencies
3:47:20 PM: Starting to download cache of 382.0MB
3:47:22 PM: Finished downloading cache in 2.322590285s
3:47:22 PM: Starting to extract cache
3:47:39 PM: Finished extracting cache in 16.202697906s
3:47:39 PM: Finished fetching cache in 18.612686279s
3:47:39 PM: Starting to prepare the repo for build
3:47:39 PM: Preparing Git Reference refs/heads/main
3:47:40 PM: Parsing package.json dependencies
3:47:41 PM: Starting build script
3:47:41 PM: Installing dependencies
3:47:41 PM: Python version set to 2.7
3:47:42 PM: Started restoring cached node version
3:47:44 PM: Finished restoring cached node version
3:47:44 PM: v12.18.0 is already installed.
3:47:45 PM: Now using node v12.18.0 (npm v6.14.4)
3:47:45 PM: Started restoring cached build plugins
3:47:45 PM: Finished restoring cached build plugins
3:47:45 PM: Attempting ruby version 2.7.1, read from environment
3:47:46 PM: Using ruby version 2.7.1
3:47:47 PM: Using PHP version 5.6
3:47:47 PM: Started restoring cached node modules
3:47:47 PM: Finished restoring cached node modules
3:47:47 PM: Started restoring cached go cache
3:47:47 PM: Finished restoring cached go cache
3:47:47 PM: go version go1.14.4 linux/amd64
3:47:47 PM: go version go1.14.4 linux/amd64
3:47:47 PM: Installing missing commands
3:47:47 PM: Verify run directory
3:47:49 PM:
3:47:49 PM: ────────────────────────────────────────────────────────────────
3:47:49 PM: Netlify Build
3:47:49 PM: ────────────────────────────────────────────────────────────────
3:47:49 PM:
3:47:49 PM: ❯ Version
3:47:49 PM: @netlify/build 11.17.2
3:47:49 PM:
3:47:49 PM: ❯ Flags
3:47:49 PM: deployId: 60a3c5663aa7a60008e68452
3:47:49 PM:
3:47:49 PM: ❯ Current directory
3:47:49 PM: /opt/build/repo
3:47:49 PM:
3:47:49 PM: ❯ Config file
3:47:49 PM: No config file was defined: using default values.
3:47:49 PM:
3:47:49 PM: ❯ Context
3:47:49 PM: production
3:47:49 PM:
3:47:49 PM: ❯ Loading plugins
3:47:49 PM: - @netlify/plugin-nextjs@3.3.0 from Netlify app
3:47:49 PM:
3:47:49 PM: ────────────────────────────────────────────────────────────────
3:47:49 PM: 1. onPreBuild command from @netlify/plugin-nextjs
3:47:49 PM: ────────────────────────────────────────────────────────────────
3:47:49 PM:
3:47:49 PM: info - Using webpack 5. Reason: no custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
3:47:50 PM: Next.js cache restored.
3:47:50 PM:
3:47:50 PM: (@netlify/plugin-nextjs onPreBuild completed in 938ms)
3:47:50 PM:
3:47:50 PM: ────────────────────────────────────────────────────────────────
3:47:50 PM: 2. Build command from Netlify app
3:47:50 PM: ────────────────────────────────────────────────────────────────
3:47:50 PM:
3:47:50 PM: $ npx nx build tuskdesk --prod --outputPath=. --runner=no-cloud
3:47:52 PM: > nx run tuskdesk:build:production --outputPath=.
3:47:55 PM: info - Using webpack 4. Reason: custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
3:47:56 PM: info - Using webpack 4. Reason: custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
3:47:56 PM: info - Checking validity of types...
3:47:59 PM: info - Creating an optimized production build...
3:48:01 PM: info - Using external babel configuration from /opt/build/repo/apps/tuskdesk/.babelrc
3:48:03 PM: info - Compiled successfully
3:48:03 PM: info - Collecting page data...
3:48:04 PM: info - Generating static pages (0/3)
3:48:04 PM: undefined
3:48:04 PM: info - Generating static pages (3/3)
3:48:04 PM: info - Finalizing page optimization...
3:48:04 PM: Page Size First Load JS
3:48:04 PM: ┌ ○ / 1.22 kB 66.6 kB
3:48:04 PM: ├ /_app 0 B 65.4 kB
3:48:04 PM: └ ○ /404 3.71 kB 69.1 kB
3:48:04 PM: + First Load JS shared by all 65.4 kB
3:48:04 PM: ├ chunks/f6078781a05fe1bcb0902d23dbbb2662c8d200b3.b8ccfd.js 13.5 kB
3:48:04 PM: ├ chunks/framework.0c3b20.js 41.8 kB
3:48:04 PM: ├ chunks/main.c7d597.js 6.88 kB
3:48:04 PM: ├ chunks/pages/_app.5f8720.js 2.47 kB
3:48:04 PM: ├ chunks/webpack.50bee0.js 751 B
3:48:04 PM: └ css/afd7172b7cfc566ac23d.css 20 B
3:48:04 PM: λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
3:48:04 PM: ○ (Static) automatically rendered as static HTML (uses no initial props)
3:48:04 PM: ● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)
3:48:04 PM: (ISR) incremental static regeneration (uses revalidate in getStaticProps)
3:48:05 PM: ———————————————————————————————————————————————
3:48:05 PM: > NX SUCCESS Running target "build" succeeded
3:48:05 PM:
3:48:05 PM: (build.command completed in 14.7s)
3:48:05 PM:
3:48:05 PM: ────────────────────────────────────────────────────────────────
3:48:05 PM: 3. onBuild command from @netlify/plugin-nextjs
3:48:05 PM: ────────────────────────────────────────────────────────────────
3:48:05 PM:
3:48:05 PM: ** Running Next on Netlify package **
3:48:05 PM: 🚀 Next on Netlify 🚀
3:48:05 PM: 🌍️ Copying public/ folder to /opt/build/repo
3:48:05 PM: 💼 Copying static NextJS assets to /opt/build/repo
3:48:05 PM: 💫 Setting up API endpoints as Netlify Functions in netlify/functions
3:48:05 PM: 💫 Setting up pages with getInitialProps as Netlify Functions in netlify/functions
3:48:05 PM: 💫 Setting up pages with getServerSideProps as Netlify Functions in netlify/functions
3:48:05 PM: 🔥 Copying pre-rendered pages with getStaticProps and JSON data to /opt/build/repo
3:48:05 PM: 💫 Setting up pages with getStaticProps and fallback: true as Netlify Functions in netlify/functions
3:48:05 PM: 💫 Setting up pages with getStaticProps and revalidation interval as Netlify Functions in netlify/functions
3:48:05 PM: 🔥 Copying pre-rendered pages without props to /opt/build/repo
3:48:05 PM: 🔀 Setting up redirects
3:48:05 PM: 🔀 Setting up headers
3:48:05 PM: ✅ Success! All done!
3:48:05 PM:
3:48:05 PM: (@netlify/plugin-nextjs onBuild completed in 32ms)
3:48:05 PM:
3:48:05 PM: ────────────────────────────────────────────────────────────────
3:48:05 PM: 4. Functions bundling
3:48:05 PM: ────────────────────────────────────────────────────────────────
3:48:05 PM:
3:48:05 PM: Packaging Functions from netlify/functions directory:
3:48:05 PM: - next_image.js
3:48:05 PM:
3:48:11 PM:
3:48:11 PM: (Functions bundling completed in 6.2s)
3:48:11 PM:
3:48:11 PM: ────────────────────────────────────────────────────────────────
3:48:11 PM: 5. onPostBuild command from @netlify/plugin-nextjs
3:48:11 PM: ────────────────────────────────────────────────────────────────
3:48:11 PM:
3:48:11 PM: Next.js cache saved.
3:48:11 PM:
3:48:11 PM: (@netlify/plugin-nextjs onPostBuild completed in 247ms)
3:48:11 PM:
3:48:11 PM: ────────────────────────────────────────────────────────────────
3:48:11 PM: 6. Deploy site
3:48:11 PM: ────────────────────────────────────────────────────────────────
3:48:11 PM:
3:48:11 PM: Starting to deploy site from '/'
3:48:13 PM: Creating deploy tree
3:48:13 PM: Creating deploy upload records
3:48:13 PM: 4 new files to upload
3:48:13 PM: 0 new functions to upload
3:48:13 PM: Site deploy was successfully initiated
3:48:13 PM:
3:48:13 PM: (Deploy site completed in 1.6s)
3:48:13 PM:
3:48:13 PM: ────────────────────────────────────────────────────────────────
3:48:13 PM: Netlify Build Complete
3:48:13 PM: ────────────────────────────────────────────────────────────────
3:48:13 PM:
3:48:13 PM: (Netlify Build completed in 24.4s)
3:48:13 PM: Starting post processing
3:48:13 PM: Post processing - HTML
3:48:13 PM: Post processing - header rules
3:48:13 PM: Post processing - redirect rules
3:48:13 PM: Post processing done
3:48:13 PM: Caching artifacts
3:48:13 PM: Started saving node modules
3:48:13 PM: Finished saving node modules
3:48:13 PM: Started saving build plugins
3:48:13 PM: Finished saving build plugins
3:48:13 PM: Started saving pip cache
3:48:14 PM: Finished saving pip cache
3:48:14 PM: Started saving emacs cask dependencies
3:48:14 PM: Finished saving emacs cask dependencies
3:48:14 PM: Started saving maven dependencies
3:48:14 PM: Site is live ✨
3:48:14 PM: Finished saving maven dependencies
3:48:14 PM: Started saving boot dependencies
3:48:14 PM: Finished saving boot dependencies
3:48:14 PM: Started saving rust rustup cache
3:48:14 PM: Finished saving rust rustup cache
3:48:14 PM: Started saving go dependencies
3:48:14 PM: Finished saving go dependencies
3:48:14 PM: Build script success
3:49:23 PM: Finished processing build request in 2m3.501079898s
failed build of 042b554e
3:51:08 PM: Build ready to start
3:51:12 PM: build-image version: 0582042f4fc261adc7bd8333f34884959c577302
3:51:12 PM: build-image tag: v3.7.6
3:51:12 PM: buildbot version: 03c6f9d243f25556225c9548fcb276f97b8bf623
3:51:12 PM: Fetching cached dependencies
3:51:12 PM: Starting to download cache of 382.1MB
3:51:17 PM: Finished downloading cache in 4.807617977s
3:51:17 PM: Starting to extract cache
3:51:34 PM: Finished extracting cache in 17.254511133s
3:51:34 PM: Finished fetching cache in 22.160368055s
3:51:34 PM: Starting to prepare the repo for build
3:51:35 PM: Preparing Git Reference refs/heads/main
3:51:35 PM: Parsing package.json dependencies
3:51:37 PM: Starting build script
3:51:37 PM: Installing dependencies
3:51:37 PM: Python version set to 2.7
3:51:38 PM: Started restoring cached node version
3:51:40 PM: Finished restoring cached node version
3:51:41 PM: v12.18.0 is already installed.
3:51:42 PM: Now using node v12.18.0 (npm v6.14.4)
3:51:42 PM: Started restoring cached build plugins
3:51:42 PM: Finished restoring cached build plugins
3:51:42 PM: Attempting ruby version 2.7.1, read from environment
3:51:44 PM: Using ruby version 2.7.1
3:51:44 PM: Using PHP version 5.6
3:51:44 PM: Started restoring cached node modules
3:51:44 PM: Finished restoring cached node modules
3:51:45 PM: Started restoring cached go cache
3:51:45 PM: Finished restoring cached go cache
3:51:45 PM: go version go1.14.4 linux/amd64
3:51:45 PM: go version go1.14.4 linux/amd64
3:51:45 PM: Installing missing commands
3:51:45 PM: Verify run directory
3:51:46 PM:
3:51:46 PM: ────────────────────────────────────────────────────────────────
3:51:46 PM: Netlify Build
3:51:46 PM: ────────────────────────────────────────────────────────────────
3:51:46 PM:
3:51:46 PM: ❯ Version
3:51:46 PM: @netlify/build 11.17.2
3:51:46 PM:
3:51:46 PM: ❯ Flags
3:51:46 PM: deployId: 60a3c64c4b5a2f0008a52a56
3:51:46 PM:
3:51:46 PM: ❯ Current directory
3:51:46 PM: /opt/build/repo
3:51:46 PM:
3:51:46 PM: ❯ Config file
3:51:46 PM: No config file was defined: using default values.
3:51:46 PM:
3:51:46 PM: ❯ Context
3:51:46 PM: production
3:51:47 PM:
3:51:47 PM: ❯ Loading plugins
3:51:47 PM: - @netlify/plugin-nextjs@3.3.0 from Netlify app
3:51:47 PM:
3:51:47 PM: ────────────────────────────────────────────────────────────────
3:51:47 PM: 1. onPreBuild command from @netlify/plugin-nextjs
3:51:47 PM: ────────────────────────────────────────────────────────────────
3:51:47 PM:
3:51:48 PM: info - Using webpack 5. Reason: no custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
3:51:48 PM: Next.js cache restored.
3:51:48 PM:
3:51:48 PM: (@netlify/plugin-nextjs onPreBuild completed in 1.3s)
3:51:48 PM:
3:51:48 PM: ────────────────────────────────────────────────────────────────
3:51:48 PM: 2. Build command from Netlify app
3:51:48 PM: ────────────────────────────────────────────────────────────────
3:51:48 PM:
3:51:48 PM: $ npx nx build tuskdesk --prod --outputPath=. --runner=no-cloud
3:51:50 PM: > nx run tuskdesk:build:production --outputPath=.
3:51:54 PM: info - Using webpack 4. Reason: custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
3:51:56 PM: info - Using webpack 4. Reason: custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
3:51:56 PM: info - Checking validity of types...
3:52:00 PM: info - Creating an optimized production build...
3:52:01 PM: info - Using external babel configuration from /opt/build/repo/apps/tuskdesk/.babelrc
3:52:04 PM: info - Compiled successfully
3:52:04 PM: info - Collecting page data...
3:52:04 PM: info - Generating static pages (0/3)
3:52:05 PM: []
3:52:05 PM: info - Generating static pages (3/3)
3:52:05 PM: info - Finalizing page optimization...
3:52:05 PM: Page Size First Load JS
3:52:05 PM: ┌ ● / 1.23 kB 66.6 kB
3:52:05 PM: ├ /_app 0 B 65.4 kB
3:52:05 PM: └ ○ /404 3.71 kB 69.1 kB
3:52:05 PM: + First Load JS shared by all 65.4 kB
3:52:05 PM: ├ chunks/f6078781a05fe1bcb0902d23dbbb2662c8d200b3.b8ccfd.js 13.5 kB
3:52:05 PM: ├ chunks/framework.0c3b20.js 41.8 kB
3:52:05 PM: ├ chunks/main.c7d597.js 6.88 kB
3:52:05 PM: ├ chunks/pages/_app.5f8720.js 2.47 kB
3:52:05 PM: ├ chunks/webpack.50bee0.js 751 B
3:52:05 PM: └ css/afd7172b7cfc566ac23d.css 20 B
3:52:05 PM: λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
3:52:05 PM: ○ (Static) automatically rendered as static HTML (uses no initial props)
3:52:05 PM: ● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)
3:52:05 PM: (ISR) incremental static regeneration (uses revalidate in getStaticProps)
3:52:06 PM: ———————————————————————————————————————————————
3:52:06 PM: > NX SUCCESS Running target "build" succeeded
3:52:06 PM:
3:52:06 PM: (build.command completed in 17.3s)
3:52:06 PM:
3:52:06 PM: ────────────────────────────────────────────────────────────────
3:52:06 PM: 3. onBuild command from @netlify/plugin-nextjs
3:52:06 PM: ────────────────────────────────────────────────────────────────
3:52:06 PM:
3:52:06 PM: ** Running Next on Netlify package **
3:52:06 PM: 🚀 Next on Netlify 🚀
3:52:06 PM: 🌍️ Copying public/ folder to /opt/build/repo
3:52:06 PM: 💼 Copying static NextJS assets to /opt/build/repo
3:52:06 PM: 💫 Setting up API endpoints as Netlify Functions in netlify/functions
3:52:06 PM: 💫 Setting up pages with getInitialProps as Netlify Functions in netlify/functions
3:52:06 PM: 💫 Setting up pages with getServerSideProps as Netlify Functions in netlify/functions
3:52:06 PM: 🔥 Copying pre-rendered pages with getStaticProps and JSON data to /opt/build/repo
3:52:06 PM:
3:52:06 PM: ────────────────────────────────────────────────────────────────
3:52:06 PM: Plugin "@netlify/plugin-nextjs" internal error
3:52:06 PM: ────────────────────────────────────────────────────────────────
3:52:06 PM:
3:52:06 PM: Error message
3:52:06 PM: Error: ENOENT: no such file or directory, stat '.next/serverless/pages/index.html'
3:52:06 PM:
3:52:06 PM: Plugin details
3:52:06 PM: Package: @netlify/plugin-nextjs
3:52:06 PM: Version: 3.3.0
3:52:06 PM: Repository: git+https://github.com/netlify/netlify-plugin-nextjs.git
3:52:06 PM: npm link: https://www.npmjs.com/package/@netlify/plugin-nextjs
3:52:06 PM: Report issues: https://github.com/netlify/netlify-plugin-nextjs/issues
3:52:06 PM:
3:52:06 PM: Error location
3:52:06 PM: In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app
3:52:06 PM: at Object.statSync (fs.js:933:3)
3:52:06 PM: at Object.statSync (/opt/build/repo/.netlify/plugins/node_modules/graceful-fs/polyfills.js:311:34)
3:52:06 PM: at statSync (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/util/stat.js:10:52)
3:52:06 PM: at getStatsSync (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/util/stat.js:24:19)
3:52:06 PM: at Object.checkPathsSync (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/util/stat.js:49:33)
3:52:06 PM: at copySync (/opt/build/repo/.netlify/plugins/node_modules/fs-extra/lib/copy-sync/copy-sync.js:24:38)
3:52:06 PM: at setupStaticFileForPage (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/src/lib/helpers/setupStaticFileForPage.js:12:3)
3:52:06 PM: at async /opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/src/lib/pages/getStaticProps/setup.js:27:5
3:52:06 PM: at async asyncForEach (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/src/lib/helpers/asyncForEach.js:3:5)
3:52:06 PM: at async setup (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/src/lib/pages/getStaticProps/setup.js:22:3)
3:52:06 PM:
3:52:06 PM: Error properties
3:52:06 PM: {
3:52:06 PM: errno: -2,
3:52:06 PM: syscall: 'stat',
3:52:06 PM: code: 'ENOENT',
3:52:06 PM: path: '.next/serverless/pages/index.html'
3:52:06 PM: }
3:52:06 PM:
3:52:06 PM: Resolved config
3:52:06 PM: build:
3:52:06 PM: command: npx nx build tuskdesk --prod --outputPath=. --runner=no-cloud
3:52:06 PM: commandOrigin: ui
3:52:06 PM: publish: /opt/build/repo
3:52:06 PM: plugins:
3:52:06 PM: - inputs: {}
3:52:06 PM: origin: ui
3:52:06 PM: package: '@netlify/plugin-nextjs'
3:52:06 PM: Caching artifacts
3:52:06 PM: Started saving node modules
3:52:06 PM: Finished saving node modules
3:52:06 PM: Started saving build plugins
3:52:06 PM: Finished saving build plugins
3:52:06 PM: Started saving pip cache
3:52:06 PM: Finished saving pip cache
3:52:06 PM: Started saving emacs cask dependencies
3:52:06 PM: Finished saving emacs cask dependencies
3:52:06 PM: Started saving maven dependencies
3:52:06 PM: Finished saving maven dependencies
3:52:06 PM: Started saving boot dependencies
3:52:06 PM: Finished saving boot dependencies
3:52:06 PM: Started saving rust rustup cache
3:52:06 PM: Finished saving rust rustup cache
3:52:06 PM: Started saving go dependencies
3:52:06 PM: Finished saving go dependencies
3:52:06 PM: Build failed due to a plugin error: Build script returned non-zero exit code: 3
3:52:06 PM: Creating deploy upload records
3:52:07 PM: Failing build: Failed to build site
3:52:07 PM: Failed during stage 'building site': Build script returned non-zero exit code: 3
3:52:07 PM: Finished processing build request in 54.634635114s
My build configuration