question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`nx serve --prod` not working with cache hit

See original GitHub issue

Current 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:closed
  • Created a year ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jaysoocommented, Jul 15, 2022

This will be fixed in the next release. For the time being, set outputPath to something else as the workaround.

{
  // ...
  "targets": {
    "build": {
      "executor": "@nrwl/next:build",
      "outputs": [
        "{options.outputPath}"
      ],
      "defaultConfiguration": "production",
      "options": {
        "root": "apps/demo",
        "outputPath": "dist/apps/demo"
      },
      "configurations": {
        "development": {
          // NOTE: Point to a different path so there aren't any collisions.
          "outputPath": "tmp/apps/demo"
        },
        "production": {}
      }
    },
    // ...
}
0reactions
Phaultcommented, Jun 23, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

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