nx
nx copied to clipboard
Dist folder not restored if no changes
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
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.
Looks related to #8504
I just updated to latest and the fix for #8504 does appear to have fixed this as well.
The problem still exists in v14.0.3.
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
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.
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.
I experiment the same problem with Nx 14.4.3 too …
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"
]
}
}
}
I am experiencing this issue on version 14.8.1
Have same issue on version 14.8.3, dist folder not created when using nx-cloud and nothing has changed.
have the same issue in 15.0.4, while using nx local cache
same here - 15.0.13
🤷♂️
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...
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.
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?
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
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
(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.
Getting this on 15.8.6
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! 🙏
not stale still an issue
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?
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.
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! 🙏
Up
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).
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! 🙏
Up
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! 🙏