"Error: ENOENT: no such file or directory" for deleted file
See original GitHub issueCurrent 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.ts
to mylibrary, change imports to use a model from lib and remove oldmy-model.model.ts
- Run
npm start
orng 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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:27
- Comments:90 (3 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.