nx: "Error: ENOENT: no such file or directory" for deleted file
Current Behavior
This is happens with 10.0.0-rc.0 (not sure if it is the same with v9 stable, maybe caused by new version?)
After moving a model (class or interface) from project to lib there is an error with npm start (and with other commands most probably as well) “Error: ENOENT: no such file or directory {{old location of the file}}”. The new model is used correctly from the typescript lib (generated lib with nx) and old file has no any references in code.
Expected Behavior
Should not be an error after file is removed in case it is not used in project source locally (it works correctly right after commit).
With a debugging trough node module I found that the core of the problem - file node_modules/@nrwl/workspace/src/core/hasher/file-hasher.js reads files not from local files but from git (and then as removed file is in git it is included and other functions tries to read it locally and crash because it is removed locally). I do not think it is expected behaviour, correct?
Steps to Reproduce
- Create an angular app with nx based on angular.
- Create a model (class or interface) somewhere inside main angular project src as a separate file (for example
my-model.model.ts) - Commit changes (not sure if push is needed)
- Create a library with
nx generate @nrwl/workspace:library mylibrary - Move
my-model.model.tsto mylibrary, change imports to use a model from lib and remove oldmy-model.model.ts - Run
npm startorng serve- and you should get an error related to removed file (logs are added below)
Failure Logs
Error: ENOENT: no such file or directory, open '/Users/my-user/PhpstormProjects/my-org/src/node/apps/main-app/src/app/core/store/models/entity.model.ts'
at Object.openSync (fs.js:443:3)
at Object.readFileSync (fs.js:343:35)
at TypeScriptImportLocator.defaultFileRead [as fileRead] (/Users/my-user/PhpstormProjects/my-org/src/node/node_modules/@nrwl/workspace/src/core/file-utils.js:150:17)
at TypeScriptImportLocator.fromFile (/Users/my-user/PhpstormProjects/my-org/src/node/node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/typescript-import-locator.js:21:30)
at Object.values.forEach (/Users/my-user/PhpstormProjects/my-org/src/node/node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/explicit-project-dependencies.js:11:27)
at Array.forEach (<anonymous>)
at Object.keys.forEach (/Users/my-user/PhpstormProjects/my-org/src/node/node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/explicit-project-dependencies.js:10:44)
at Array.forEach (<anonymous>)
at buildExplicitTypeScriptDependencies (/Users/my-user/PhpstormProjects/my-org/src/node/node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/explicit-project-dependencies.js:9:30)
at buildDependenciesFns.forEach (/Users/my-user/PhpstormProjects/my-org/src/node/node_modules/@nrwl/workspace/src/core/project-graph/project-graph.js:61:41)
Environment
@nrwl/angular : 10.0.0-rc.0 @nrwl/cli : 10.0.0-rc.0 @nrwl/cypress : 10.0.0-rc.0 @nrwl/eslint-plugin-nx : Not Found @nrwl/express : Not Found @nrwl/jest : 10.0.0-rc.0 @nrwl/linter : Not Found @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : Not Found @nrwl/react : Not Found @nrwl/schematics : Not Found @nrwl/tao : 10.0.0-rc.0 @nrwl/web : Not Found @nrwl/workspace : 10.0.0-rc.0 typescript : 3.9.7
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 27
- Comments: 91 (11 by maintainers)
SOLVED but unhappy with the outcome
I’ve deleted an angular component that was generated using the CLI. Im getting the same error now even when I try to run a different app in the workspace.
node v14.3.0 yarn 1.22.4 nx 10.0.0
From the docs “By default, Nx uses a local computation cache. The cache is stored in node_modules/.cache/nx. […] Nx stores the cached values only for a week, after which they are deleted. To clear the cache, delete the cache directory, and Nx will create a new one next time it tries to access it.”
I’ve manually deleted the ‘.cache/nx’ folder. No success I’ve manually deleted all node_modules folder and reinstalled. No success I’ve run multiple commands using --skip-nx-cache. No success I’ve changed the cacheDirectory. No success
As the fellow reporter stated, this is NOT related to NX caching inside node_modules.
Eventually, I committed my changes in git. After this, everything started working again.
Now what if I did not want to commit, Should we follow any specific process to delete or rename a file? Should we document this as Common Problems?
Problem still occurs in version 12.0.6.
Renaming, moving or deleting files leads to this issue. Committing the changes to the local git repository serves as a workaround.
For anyone still experiencing this issue, check the
workspace.jsonfile. For me, there was a reference to the deleted folder in there. Removing the reference fixed it.As this has been an ongoing request and not being addressed, I decided to open another ticket related to this bug here https://github.com/nrwl/nx/issues/6370
Hope this bug will finally get visibility and higher priority. @vsavkin and any NX maintainers (@FrozenPandaz?).
I did analyze the problem:
The problem is in @nrwl/workspace, in version 11:
It occurs when the nx root folder isn’t the git root folder (e.g. in a monorepo the nx root folder is a sub folder in the git tree).
When checking the project dependencies with the git hasher (git-hasher.js), git status is used to get the current changed/added/deleted files. The deleted files are removed from the complete file list (git ls), but there is the problem:
The list of files from get status is based on the root git folder, the files from git ls are based on the sub folder where nx is installed.
When fixed correctly it will also solve the issue with “Warning: Fell back to using ‘fs’ to identify ${f} as deleted. Please open an issue at https://github.com/nrwl/nx so we can investigate.”
==============================================
Looking at the current code: This issue should is fixed at 24/3/2021, and should be solved in version 12.0.0
+1 to reopening this issue, please. It is detrimental to developer workflows and this is reason enough to stop using the tool.
This issue has not resolved yet… Please reopen the issue
@Bullsized it’s not upvoted because it’s not a solution it just avoiding the issue. We are looking for solutions here. The best would be if NRWL team would be willing to fix this issue. This is clearly a huge bug.
I would just add that git commit is not a solution but a workaround. I encounter this issue daily and it’s quite annoying while doing refactorings in a codebase.
Try
git stashandgit stash pop. It work for me.Still happening on 11.5.2 (nx React) with @nrwl/workspace@11.5.2 after renaming a file.
I do not know a workaround. Even removing the NPM cache does not help at all.
@vsavkin Any suggestions?
I’m having the same issue @10.0.2, I tracked down to
file-hasher/getHashesFromGit().The
allFiles()function returns an array containing both the old location and the new location for moved files. This only happens to files that are staged on git.Repro steps
Now, just run
nx serveand a wild error appears.Workaround
Just unstage the git files.
I spent almost 4 hours to discover thisThis is still an issue in
"@nrwl/workspace": "12.6.0-rc.0". I do NOT have a monorepo as subfolder in a git folder. My root folder is the monorepo.git stashseems to work as a workaround as suggested. @joepjoosten @brandonrobertsI have the same issue, the nrwl workspace is a sub folder in the git tree. Please reopen the issue, its important for the developer workflows to work with it.
“@angular/cli”: “^11.2.14”, “@nrwl/workspace”: “12.2.0”,
Not working in 10.0.6
Folks, sorry about this. I fixed the issue in Nx 10.0.2.
If you can still reproduce the issue in 10.0.2, please provide a repo that I can take a loot at.
Still happening on 11.6.0 after deleting a file 😦
@vsavkin for scenario when some file is just removed it seems to be ok. But when I move file to other location (in my case from app to lib) - it is still the same error.
Simple way to replicate:
Same here, this is really strange behavior. I would not expect it is something related to git. Simple git commit fixed the case. I would strongly recommend addressing this issue as lots of developers have similar problems.
still happening in
"@nrwl/workspace": "12.3.6". please re-open the issue @vsavkinFor me, it happens on a file rename that doesn’t exist in
master. So, I created a component in a branch and commit it. then I rename the component file name. I can’t run serve anymore.,@nrwl/cli v12.3.3 - problem persists, commit/stash fixes the issue
I can still reproduce this on @nrwl/workspace 10.0.7.
Steps to reproduce:
Same for me.
Same version here. It happens whenever I rename or move a file or dir. I have to commit a incomplete work to continue working.
@mukaschultze could you try 10.0.4? Thank you!
Yes, happening very often. we are seeing it after we migrate to v12.
Nx use “git ls-tree HEAD -r” command for get list of files in last commit, then comparing this with actual state of repo, so from my point of view, if file is messing Nx need to skip this compare and sign module for rebuild.
Same here, just migrated to 10.0.1 and then I renamed a module and I’m getting this now. Is there cache that we can manually invalidate to work around?
Still getting this problem in nx v12 But this worked for me
rm -r -f node_modules/ && rm package-lock.json && npm cache clean --forceWhy this ticket is closed, i still have this problem.
hey guuuuus, just fixed with the stash , try git stash , its work for me
Not working here in 10.0.6.
Only committing the file helps as workaround.
Same error for me after deleting a service.
Can confirm that it is likely related to hashing git files.
A potential workaround is to commit your changes on your local branch, or provide an older --base / --head
happening with v10 stable as well:
simple reproduction:
npx create-nx-workspace@latestwith Angular appnpm run lintapp.component.spec.tsnpm run lintagainfor anyone still having issues:
renaming a file and having that over staging (git) was the issue, I commited the rename only and it’s OK now.
Is this getting any traction?
Same issue as everyone else. Apple M1 silicon. And Windows 11
Happens for me with
13.8.1. I moved file into another library. And now nx linter does not want to catch this. It keeps thinking the file is in old location. And even stash / commit does not help. Weird…Thank you!, You save my life 😄
Same here, git commit helped, but I didn’t want it
Happened once with me after moving a file to another folder.
git committhen everything is fine.still happens on 10.4.4
the framework could be a bit more pro-active in delivering pre configured paths and lint rules for the project
after project creation lands
Same happens with nx 10.3.1 after deleting schematics template files and not committing.
Still happening on nx 10.3.0
Seems like the issue is gone for “@nrwl/workspace”: “10.0.7”
had the same, tracked @nrwl/workspace->project-graph … etc etc … after a while i backed my changes with a commit
maybe you could add handling for staged files (marked as deleted, renamed, etc…)