Next.js 12 Output File Tracing Fails to Build
See original GitHub issueCurrent Behavior
- create a new nx workspace w/ a next.js app
- turn on next.js output file tracing
- run
nx build --prod
- build fails w/ the error message saying
dist/apps/haha/.next/standalone/apps/haha/server.js
doesn’t exist (it doesn’t)
Expected Behavior
The standalone
folder should contain a server.js
file.
Steps to Reproduce
I’ve created a repro repo here. Clone & run yarn nx build --prod
to see error message.
Failure Logs
ENOENT: no such file or directory, open '/nx_next_standalone_repro/dist/apps/haha/.next/standalone/apps/haha/server.js'
Environment
Output of next info
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.2.0: Sun Nov 28 20:29:10 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T8101
Binaries:
Node: 16.13.1
npm: 8.1.2
Yarn: 1.22.17
pnpm: N/A
Relevant packages:
next: 12.1.0
react: 17.0.2
react-dom: 17.0.2
Output of nx report
Node : 16.13.1
OS : darwin arm64
yarn : 1.22.17
nx : 13.8.2
@nrwl/angular : undefined
@nrwl/cli : 13.8.2
@nrwl/cypress : 13.8.2
@nrwl/detox : undefined
@nrwl/devkit : 13.8.2
@nrwl/eslint-plugin-nx : 13.8.2
@nrwl/express : undefined
@nrwl/jest : 13.8.2
@nrwl/js : 13.8.2
@nrwl/linter : 13.8.2
@nrwl/nest : undefined
@nrwl/next : 13.8.2
@nrwl/node : undefined
@nrwl/nx-cloud : undefined
@nrwl/react : 13.8.2
@nrwl/react-native : undefined
@nrwl/schematics : undefined
@nrwl/storybook : 13.8.2
@nrwl/tao : 13.8.2
@nrwl/web : 13.8.2
@nrwl/workspace : 13.8.2
typescript : 4.5.5
rxjs : 6.6.7
---------------------------------------
Community plugins:
Issue Analytics
- State:
- Created 2 years ago
- Reactions:28
- Comments:56 (1 by maintainers)
Top Results From Across the Web
Advanced Features: Output File Tracing - Next.js
During a build, Next.js will automatically trace each page and its dependencies to determine all of the files that are needed for deploying...
Read more >I am getting error while converting my next js project to docker
The Dockerfile I got from the next js github page worked fine for me and I got a build successfully. # Install dependencies...
Read more >[Node] Next.js with @newrelic/next and outputStandalone
Hello all, I've been playing around with New Relic's Next.js ... this in combination with Next.js's experimental Output File Tracing feature ...
Read more >Serverless SSR with React 18 and NextJS 12 in AWS
When building serverless applications we still want to use modern frontend ... Output File Tracing is a feature of NextJS that analyses ...
Read more >What's new in Next.js 12 - LogRocket Blog
Output file tracing ... This has been improved by bringing Vercel's @verce/nft package to Next.js 12. With this, Nextjs can automatically trace ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just don’t ask how I investigated this and how much time I spend to find out how to fix this. ⚠️ WARNING ⚠️ Next text for people who believe in magic, skeptics, please stop read this text right now. I warned you.
Steps to get working repo for standalone Next.js server with build using NX CLI.
Init example workspace (or use your own)
npx create-nx-workspace@latest --preset=next
(tested on v14.1.9 workspace)next.config.js
file and add to config:Preparation finished, now let’s make real magic
Go to
pages/index.tsx
(or any page file) and add this lines (don’t ask why, this is MAGIC):Really can be any js file that can be resolved from current location (even empty). This code enough to insert only once.
Show magic to the world
Run
npm run build
. That’s it! No errors!Bonus
This is a VERY SIMPLE Docker config that show how to work with this build.
Thanks to @bboyz269 for working example, from his repository I found the issue why build didn’t work on clean project. His repo works because of
next-i18next
lib code.I post mine maybe it helps