Command to build Next.js for Vercel errors out

See original GitHub issue

Current Behavior

Command fails

Expected Behavior

I expected it to build my project successfully

Steps to Reproduce

Repo: https://github.com/Xenfo/atomic Try to deploy it to Vercel following the guide in the NX Next.js docs.

Failure Logs

❯ nx build frontend --prod --outputPath=.

> nx run frontend:build:production --outputPath=. 
info  - Using webpack 4. Reason: custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
info  - Using webpack 4. Reason: custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
info  - Checking validity of types  
info  - Using external babel configuration from /home/xenfo/Desktop/Projects/atomic/apps/frontend/.babelrc
info  - Creating an optimized production build  
info  - Compiled successfully
info  - Collecting page data  
info  - Generating static pages (3/3)
info  - Finalizing page optimization  

Page                                                           Size     First Load JS
┌ ○ /                                                          1.22 kB        68.4 kB
├   └ css/f06ddab96869c260cfa8.css                             20 B
├   /_app                                                      0 B            67.2 kB
└ ○ /404                                                       3.73 kB        70.9 kB
+ First Load JS shared by all                                  67.2 kB
  ├ chunks/f6078781a05fe1bcb0902d23dbbb2662c8d200b3.9f24d5.js  13.6 kB
  ├ chunks/framework.0c3b20.js                                 41.8 kB
  ├ chunks/main.bab312.js                                      6.95 kB
  ├ chunks/pages/_app.4b9835.js                                4.15 kB
  ├ chunks/webpack.50bee0.js                                   751 B
  └ css/48cbfac088811e35fdc5.css                               667 B

λ  (Server)  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)


———————————————————————————————————————————————

>  NX   ERROR  Running target "frontend:build" failed

  Failed tasks:
  
  - frontend:build:production


>  NX   CLOUD  See run details at ...

Environment

Node : 14.15.5
OS   : linux x64
yarn : 1.22.5
  
nx : Not Found
@nrwl/angular : Not Found
@nrwl/cli : 12.3.4
@nrwl/cypress : 12.3.4
@nrwl/devkit : 12.3.4
@nrwl/eslint-plugin-nx : 12.3.4
@nrwl/express : 12.3.4
@nrwl/jest : 12.3.4
@nrwl/linter : 12.3.4
@nrwl/nest : Not Found
@nrwl/next : 12.3.4
@nrwl/node : 12.3.4
@nrwl/react : 12.3.4
@nrwl/schematics : Not Found
@nrwl/tao : 12.3.4
@nrwl/web : 12.3.4
@nrwl/workspace : 12.3.4
@nrwl/storybook : 12.3.4
@nrwl/gatsby : Not Found
typescript : 4.2.4

Workaround from Vercel

Set custom build command to: npx nx build my-app --prod Set output directory to: dist/apps/my-app/.next

Note for this to work you must have NX Cloud off as far as I can tell

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:19 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
Xenfocommented, May 24, 2021

@hcharley Just want to note that when Vercel tries to build with NX build cache it fails, so if you try to rebuild it probably won’t work.


13:49:13.503 | Cloning github.com/Xenfo/atomic (Branch: dev, Commit: 9ee2551)
-- | --
13:49:13.792 | Cloning completed: 288.897ms
13:49:13.830 | Analyzing source code...
13:49:15.052 | Installing build runtime...
13:49:18.644 | Build runtime installed: 3.592s
13:49:21.635 | Looking up build cache...
13:49:22.003 | Build cache found. Downloading...
13:49:26.619 | Build cache downloaded [60.43 MB]: 4615.908ms
13:49:27.874 | Installing dependencies...
13:49:28.319 | yarn install v1.22.10
13:49:28.445 | [1/4] Resolving packages...
13:49:29.393 | success Already up-to-date.
13:49:29.397 | $ is-ci \|\| husky install
13:49:29.526 | Done in 1.21s.
13:49:29.545 | Detected Next.js version: 10.2.2
13:49:29.786 | Running "yarn nx run frontend:build-css && yarn nx build frontend --prod && rm -rf package.json && mv -v dist/apps/frontend/.next .next && mv -v dist/apps/frontend/package.json package.json && mv -v dist/apps/frontend/next.config.js next.config.js"
13:49:30.144 | yarn run v1.22.10
13:49:30.185 | $ nx run frontend:build-css
13:49:30.961 | > nx run frontend:build-css
13:49:31.471 | $ /vercel/path0/node_modules/.bin/postcss /vercel/path0/apps/frontend/src/styles/main.css -o /vercel/path0/apps/frontend/src/styles/tailwind.css
13:49:32.307 | warn - You have enabled the JIT engine which is currently in preview.
13:49:32.308 | warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time.
13:49:32.656 | ———————————————————————————————————————————————
13:49:32.656 | >  NX   SUCCESS  Running target "build-css" succeeded
13:49:32.665 | >  NX   CLOUD  See run details at https://nx.app/runs/8xVsN1Ln6w2
13:49:32.682 | Done in 2.55s.
13:49:33.055 | yarn run v1.22.10
13:49:33.101 | $ nx build frontend --prod
13:49:33.583 | > nx run frontend:build:production
13:49:35.448 | info  - Using webpack 4. Reason: custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
13:49:35.676 | withNx() plugin: Detected Vercel build environment, applying "experimental-serverless-trace" target
13:49:36.123 | info  - Using webpack 4. Reason: custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
13:49:36.148 | Attention: Next.js now collects completely anonymous telemetry regarding usage.
13:49:36.148 | This information is used to shape Next.js' roadmap and prioritize features.
13:49:36.148 | You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
13:49:36.148 | https://nextjs.org/telemetry
13:49:36.203 | info  - Checking validity of types...
13:49:39.198 | info  - Creating an optimized production build...
13:49:40.460 | info  - Using external babel configuration from /vercel/path0/apps/frontend/.babelrc
13:49:43.901 | warn - You have enabled the JIT engine which is currently in preview.
13:49:43.901 | warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time.
13:49:49.886 | info  - Compiled successfully
13:49:49.886 | info  - Collecting page data...
13:49:50.208 | info  - Generating static pages (0/3)
13:49:50.508 | info  - Generating static pages (3/3)
13:49:50.508 | info  - Finalizing page optimization...
13:49:50.524 | Page                                                           Size     First Load JS
13:49:50.524 | ┌ ○ /                                                          1.2 kB         68.6 kB
13:49:50.524 | ├   /_app                                                      0 B            67.4 kB
13:49:50.524 | └ ○ /404                                                       3.73 kB        71.2 kB
13:49:50.524 | + First Load JS shared by all                                  67.4 kB
13:49:50.524 | ├ chunks/f6078781a05fe1bcb0902d23dbbb2662c8d200b3.2702ed.js  13.6 kB
13:49:50.524 | ├ chunks/framework.0c3b20.js                                 41.8 kB
13:49:50.524 | ├ chunks/main.19ac90.js                                      7.2 kB
13:49:50.524 | ├ chunks/pages/_app.256e46.js                                4.16 kB
13:49:50.525 | ├ chunks/webpack.50bee0.js                                   751 B
13:49:50.525 | └ css/ed7e1c278348e35aaa70.css                               1.78 kB
13:49:50.525 | λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
13:49:50.525 | ○  (Static)  automatically rendered as static HTML (uses no initial props)
13:49:50.525 | ●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
13:49:50.525 | (ISR)     incremental static regeneration (uses revalidate in getStaticProps)
13:49:50.525 | Next.js Analytics is enabled for this production build. You'll receive a Real Experience Score computed by all of your visitors.
13:49:51.172 | ———————————————————————————————————————————————
13:49:51.173 | >  NX   SUCCESS  Running target "build" succeeded
13:49:51.179 | >  NX   CLOUD  See run details at https://nx.app/runs/wzs3i3GzYkZ
13:49:51.185 | Done in 18.14s.
13:49:51.199 | ‘dist/apps/frontend/.next’ -> ‘.next/.next’
13:49:51.201 | ‘dist/apps/frontend/package.json’ -> ‘package.json’
13:49:51.202 | ‘dist/apps/frontend/next.config.js’ -> ‘next.config.js’
13:49:51.210 | Error: The file "/vercel/path0/.next/routes-manifest.json" couldn't be found. This is normally caused by a misconfiguration in your project.
13:49:51.210 | Please check the following, and reach out to support if you cannot resolve the problem:
13:49:51.210 | 1. If present, be sure your `build` script in "package.json" calls `next build`.  2. Navigate to your project's settings in the Vercel dashboard, and verify that the "Build Command" is not overridden, or that it calls `next build`.  3. Navigate to your project's settings in the Vercel dashboard, and verify that the "Output Directory" is not overridden. Note that `next export` does **not** require you change this setting, even if you customize the `next export` output directory. Learn More: https://err.sh/vercel/vercel/now-next-routes-manifest
3reactions
hcharleycommented, May 24, 2021

@Xenfo I can confirm that using the cache fails with my method.

Without the cache, my method still works.

It’s still a workaround, so yes @kirjai understanding why --outputPath=. is not working, would be helpful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot a Build – Vercel Docs
is run in the local console for a Next. js project, the error happens after building locally. Error in local console.
Read more >
Deploying NextJS to Vercel failed - Stack Overflow
Sometimes Vercel acts wired that my codes run locally(npm run dev) but fail after upload. This happens when I use Github automatic ...
Read more >
Next.js CLI
The Next.js CLI allows you to start, build, and export your application. To get a list of the available CLI commands, run the...
Read more >
Deploying NextJS to Vercel failed - Reddit
Deploying NextJS to Vercel failed. deployment fail on vercel : ... [07:46:46.334] Error: Command "yarn run build" exited with 1.
Read more >
Next.js build is failing - Render community
My Nextjs build keeps failing, although it works fine locally. ... /next/dist/build/tracer.js:1:1441 Jun 22 05:07:47 PM error Command failed ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found