`nx serve --prod` not working with cache hit
See original GitHub issueCurrent Behavior
When the build is retrieved from cache, nx serve --prod
does not work
Expected Behavior
nx serve --prod
should always work, even when the cache is hit for retrieving the build
Steps to Reproduce
npx create-nx-workspace@latest repo --preset=next
cd repo
nx generate @nrwl/next:application webapp
// Commands sequence
nx serve
nx serve --prod
// Error (expected): "Could not start production server. Try building your app with `nx build webapp`."
nx build
nx serve --prod
// Now, let's re-do the exact same flow
nx serve
nx build
// Build is instant as expected because it is retrieved from cache
nx serve --prod
// Error (unexpected): "Could not start production server. Try building your app with `nx build webapp`."
Environment
Node : 16.15.0 OS : darwin arm64 pnpm : 7.1.0
nx : 14.1.5 @nrwl/angular : Not Found @nrwl/cypress : 14.1.5 @nrwl/detox : Not Found @nrwl/devkit : 14.1.5 @nrwl/eslint-plugin-nx : 14.1.5 @nrwl/express : Not Found @nrwl/jest : 14.1.5 @nrwl/js : 14.1.5 @nrwl/linter : 14.1.5 @nrwl/nest : Not Found @nrwl/next : 14.1.5 @nrwl/node : Not Found @nrwl/nx-cloud : Not Found @nrwl/nx-plugin : Not Found @nrwl/react : 14.1.5 @nrwl/react-native : Not Found @nrwl/schematics : Not Found @nrwl/storybook : 14.1.5 @nrwl/web : 14.1.5 @nrwl/workspace : 14.1.5 typescript : 4.6.4 rxjs : 6.6.7
Issue Analytics
- State:
- Created a year ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How Caching Works - Nx
Nx sets up hooks to collect stdout/stderr before running the command. All the output is cached and then replayed during a cache hit....
Read more >Distributed Caching in Nx - Nx Blog
Without making any changes to that app or its dependencies, you re-build it. Then that build will hit the cache and appear in...
Read more >How to clear Nx cache - Stack Overflow
Just delete the whole 'nx' cache folder: rm -rf ./node_modules/.cache/nx.
Read more >nrwl-nx/community - Gitter
Hi, are there any guidelines on debugging nx caching issues? The issue i'm facing right now is that changing a dependncy does not...
Read more >Troubleshoot issues with CloudFront custom object caching
If the X-Cache header is "Hit from cloudfront" or "RefreshHit from cloudfront," then the request was served from the cache of the edge...
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
This will be fixed in the next release. For the time being, set
outputPath
to something else as the workaround.Pretty big issue I’d say, as this can lead to shipping broken production builds. In our case the CI built production builds, then ran e2e tests which mistakenly was testing with serve:development, if tests succeeded it would deploy. That’s obviously not great, but the deploy step was dependent on build:production, so it should’ve been all good. Nx said there was a cache hit but the development build would end up deployed.
Nothing is actually in production yet, so no real harm done.