nx icon indicating copy to clipboard operation
nx copied to clipboard

Dist folder not restored if no changes

Open jasedwards opened this issue 3 years ago • 33 comments

Current Behavior

On our CI if a build is kicked off with no changes (actually even with a change in a scss file in one case) then the dist folder is not restored. You get a message that "Nx read the output from cache instead of running the command for 1 out of 1 tasks". For our case the CI shares a cache directory but pulls down a brand new instance of our repo each time. Because of this there is no output folder and the post build steps fail (we zip up the app from dist) since not dist folder exists. Previous versions of nx (< 13) still created the dist folder.

Expected Behavior

output is built even if it is just copied from cache.

Steps to Reproduce

just create a new repo with an app. Build, delete dist folder and then build again.

Environment

Node : 14.17.0
OS : win32 x64
npm : 6.14.13

nx : 13.4.5
@nrwl/angular : 13.4.5
@nrwl/cli : 13.4.5
@nrwl/cypress : 13.4.5
@nrwl/devkit : 13.4.5
@nrwl/eslint-plugin-nx : 13.4.5
@nrwl/express : undefined
@nrwl/jest : 13.4.5
@nrwl/linter : 13.4.5
@nrwl/nest : undefined
@nrwl/next : undefined
@nrwl/node : undefined
@nrwl/nx-cloud : undefined
@nrwl/react : undefined
@nrwl/react-native : undefined
@nrwl/schematics : undefined
@nrwl/tao : 13.4.5
@nrwl/web : undefined
@nrwl/workspace : 13.4.5
@nrwl/storybook : 13.4.5
@nrwl/gatsby : undefined
typescript : 4.4.4
rxjs : 7.4.0

Community plugins:
@angular/animations: 13.1.2
@angular/common: 13.1.2
@angular/compiler: 13.1.2
@angular/core: 13.1.2
@angular/forms: 13.1.2
@angular/platform-browser: 13.1.2
@angular/platform-browser-dynamic: 13 @angular/router: 13.1.2
@angular-devkit/build-angular: 13.1.3 @angular/cli: 13.1.3
@angular/compiler-cli: 13.1.2
@angular/language-service: 13.1.2
@storybook/angular: 6.4.13

jasedwards avatar Jan 20 '22 13:01 jasedwards

One update on above. I mentioned that at one point it did not generate the dist folder even though I changed an scss file. this part was fixed by adding the libs/styles folders to implicit dependencies in nx.json. so it appears this is just a problem if there were no changes.

jasedwards avatar Jan 20 '22 16:01 jasedwards

Looks related to #8504

allistairec avatar Jan 28 '22 14:01 allistairec

I just updated to latest and the fix for #8504 does appear to have fixed this as well.

jasedwards avatar Feb 01 '22 16:02 jasedwards

The problem still exists in v14.0.3.

mszmida avatar Apr 29 '22 18:04 mszmida

Hello, I updated to latest and cache restoration is still not working. Here is my config:

Node : 16.14.0
OS   : win32 x64
npm  : 8.5.2

nx : 14.1.5
@nrwl/angular : 14.1.5
@nrwl/cypress : 14.1.5
@nrwl/devkit : 14.1.5
@nrwl/eslint-plugin-nx : 14.1.5
@nrwl/jest : 14.1.5
@nrwl/js : 14.1.5
@nrwl/linter : 14.1.5
@nrwl/node : 14.1.5
@nrwl/nx-cloud : 14.0.3
@nrwl/storybook : 14.1.5
@nrwl/workspace : 14.1.5
typescript : 4.5.5

GrandSchtroumpf avatar May 16 '22 09:05 GrandSchtroumpf

Hi, I created new project with nx version 14.3.6 and it seems problem is still here. If I delete folder and run build again with nx, it's not restored until some changes are made. This will cause dependent tasks fail.

Nodonisko avatar Jun 27 '22 17:06 Nodonisko

I did also experiment with remote cache, I cleaned whole project with git clean -dfx then run nx and I got green for all build tasks with message [remote cache], but folder is not restored so dependent tasks fails.

Nodonisko avatar Jun 27 '22 17:06 Nodonisko

I experiment the same problem with Nx 14.4.3 too …

tapesec avatar Aug 11 '22 13:08 tapesec

As a workaround I added the dist folder to the inputs, basically telling NX that it should consider the dist folder (but not its contents) when determining whether or not something has changed.

This will cause a cache miss; causing a rebuild; causing the dist folder to appear.

package.json


  "nx": {
    "namedInputs": {
      "default": [
        "{projectRoot}/**/*",
        "{projectRoot}/dist"
      ]
    },
    "targets": {
      "build": {
        "inputs": [
          "default"
        ]
      }
    }
  }

charlesvg avatar Aug 13 '22 13:08 charlesvg

I am experiencing this issue on version 14.8.1

sheakelly avatar Sep 30 '22 06:09 sheakelly

Have same issue on version 14.8.3, dist folder not created when using nx-cloud and nothing has changed.

dewiktor2 avatar Oct 12 '22 10:10 dewiktor2

have the same issue in 15.0.4, while using nx local cache

royi-frontegg avatar Nov 02 '22 08:11 royi-frontegg

same here - 15.0.13 🤷‍♂️

kraklin avatar Nov 15 '22 14:11 kraklin

It does feel like a big bug no? It means that we cannot use nx-cloud as the outcome of the distributed cache is not written in the dist folder...

GrandSchtroumpf avatar Nov 16 '22 14:11 GrandSchtroumpf

We encountered this issue, and found a resolution. We were using namedInputs to define keys for use in inputs and outputs, but it turns out these keys are not valid in outputs. Removing namedInputs keys from outputs seemed to resolve our issues.

matthias-ccri avatar Feb 07 '23 23:02 matthias-ccri

This usually happens if your outputs are not specified correctly. If this is the case, then Nx will believe that nothing is cached and there is nothing to restore.

Can someone please provide a repo where this issue can be reproduced?

FrozenPandaz avatar Feb 28 '23 23:02 FrozenPandaz

I'm using 14.8.4 and am also seeing this. While I don't have a full repo to share at the moment, the configuration we are using outputs the build artifacts to a folder we use to deploy many things from, which is outside of the workspace. Here's a sample from a project.json in the workspace:

"outputs": ["{options.outputPath}"],
"options": {
    "outputPath": "../content/apps/test-app",

The non-cached builds work fine and output to the folder, but restoring from cache does not despite indicating that it read from cache. The behavior is similar to this feature issue: https://github.com/nrwl/nx/issues/5433

colinparker-er avatar Mar 08 '23 16:03 colinparker-er

Was able to fix the issue by specifying the outputs directly to the project root dist folder in the nx.json file:

"targetDefaults": {
     "build": {
      "dependsOn": ["^build"],
      "outputs": ["{projectRoot}/dist"]
    }
}

nx v15.8.5

talzach avatar Mar 09 '23 07:03 talzach

(Nx 15.0.13)

Hi, also having issues with this. Feels like something is quite off - I don't have a simple repro, but exactly the behaviour people are describing here.

Unfortunately, specifying outputs in nx.json hasn't fixed things.

UPDATE The fix that @charlesvg suggested hasn't worked either for me.

arlobryer avatar Mar 16 '23 19:03 arlobryer

Getting this on 15.8.6

damiangreen avatar Mar 21 '23 10:03 damiangreen

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] avatar Apr 05 '23 00:04 github-actions[bot]

not stale still an issue

damiangreen avatar Apr 06 '23 08:04 damiangreen

This usually happens if your outputs are not specified correctly. If this is the case, then Nx will believe that nothing is cached and there is nothing to restore.

Can someone please provide a repo where this issue can be reproduced?

can you give us instructions on how to correctly specify outputs?

neilsoult avatar Apr 20 '23 17:04 neilsoult

This usually happens if your outputs are not specified correctly. If this is the case, then Nx will believe that nothing is cached and there is nothing to restore.

Can someone please provide a repo where this issue can be reproduced?

It would be great to see at least one example of a properly configured output.

vglazov-tulaco avatar Apr 25 '23 04:04 vglazov-tulaco

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] avatar May 10 '23 00:05 github-actions[bot]

Up

tonivj5 avatar May 10 '23 08:05 tonivj5

I just started getting this issue as well. In my case at least, when I run "server", it builds the server files correctly. But when I run "serve-ssr" after, it is deleting the relevant subdirectory in the dist directory along with the server folder, which seems like it's resulting in the error.

EDIT: I reinstalled @nguniversal/builders, and rebuilt my project a few times, and it seems to be resolved (after some weird errors and behavior the first couple of times).

scarryaa avatar May 16 '23 13:05 scarryaa

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] avatar May 31 '23 00:05 github-actions[bot]

Up

tonivj5 avatar May 31 '23 05:05 tonivj5

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] avatar Jun 15 '23 00:06 github-actions[bot]