-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Current Behavior
If the outputPath for a project points to a directory outside the workspace, initial builds work correctly and build artifacts are created in the desired directory. However, if the output directory is removed, it will not be recreated when building a second time. Nx will say "Nx read the output from the cache instead of running the command for 1 out of 1 tasks.", but the output will not appear in the output directory.
Expected Behavior
When using the cache, Nx should correctly output to the build directory, regardless of location. (Or if this is not supportable, then caching should be implicitly bypassed for output dirs outside the workspace... Or at least an error recommending --skip-nx-cache should be printed.)
GitHub Repo
No response
Steps to Reproduce
- Create a fresh workspace with npx create-nx-workspace; I creatively named my project "test"; I chose an angular project but I don't believe the project type or any specific settings here matter
- npm install
- npx nx build (just to verify that everything works so far)
- Now edit the outputPath in project.json to start with "../" (so for example "../dist/test")
- npx nx build (this will output the artifacts to ../dist/test as expected)
- Now delete ../dist/test
- npx nx build (this will claim to complete but ../dist/test will not be repopulated)
The build will not work correctly again until something else triggers the cache to be seen as dirty.
Nx Report
Node : 20.18.0
OS : win32-x64
Native Target : x86_64-windows
npm : 10.8.2
nx : 21.2.0
@nx/js : 21.2.0
@nx/jest : 21.2.0
@nx/eslint : 21.2.0
@nx/workspace : 21.2.0
@nx/angular : 21.2.0
@nx/devkit : 21.2.0
@nx/eslint-plugin : 21.2.0
@nx/module-federation : 21.2.0
@nx/playwright : 21.2.0
@nx/rspack : 21.2.0
@nx/web : 21.2.0
@nx/webpack : 21.2.0
typescript : 5.8.3
---------------------------------------
Registered Plugins:
@nx/playwright/plugin
@nx/eslint/plugin
---------------------------------------
Community plugins:
angular-eslint : 20.0.0
---------------------------------------
Cache Usage: 558.43 KB / 95.21 GB
Failure Logs
Package Manager Version
No response
Operating System
- macOS
- Linux
- Windows
- Other (Please specify)
Additional Information
I traced this down to the behavior of getFilesForOutputs and expandOutputs in the native nx modules (I can't seem to find the source for those to trace it any further.) When those functions take relative paths which point outside the current workspace, they will omit those. For example:
expandOutputs("<path-to-a-workspace>",["../dist", "dist/apps"])
will return only ["dist/apps"]. getFilesForOutputs seems to have similar behavior.
It looks like this has been an issue for a while - see #8614 (comment) Just like the other developer in that post, we use nx as one piece in a larger context and we assemble our build outputs outside the workspace, so supporting this fully is important to us. (Having said that, we've been using nx for a while and just noticed it; I think maybe because caching only started working for us recently. For now we will use the --skip-nx-cache flag to work around this.)