question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Error: ENOENT: no such file or directory" for deleted file

See original GitHub issue

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

  1. Create an angular app with nx based on angular.
  2. Create a model (class or interface) somewhere inside main angular project src as a separate file (for example my-model.model.ts)
  3. Commit changes (not sure if push is needed)
  4. Create a library with nx generate @nrwl/workspace:library mylibrary
  5. Move my-model.model.ts to mylibrary, change imports to use a model from lib and remove old my-model.model.ts
  6. Run npm start or ng 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:closed
  • Created 3 years ago
  • Reactions:27
  • Comments:90 (3 by maintainers)

github_iconTop GitHub Comments

41reactions
sestevacommented, Jul 21, 2020

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?

19reactions
talbxcommented, Apr 21, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

using unlinkAsync file deleted and throws Error: ENOENT: no ...
using unlinkAsync file deleted and throws Error: ENOENT: no such file or directory, open 'E:\Mern Stack\udyog-asha\backend\public\cs.word.pdf'.
Read more >
Node FS - Delete a File using unlink() or unlinkSync() functions
Example 3 – File specified to delete is not present. (Error: ENOENT: no such file or directory). For this example, make sure there...
Read more >
How To Fix the “Enoent” Error? - Position Is Everything
You can get this error if you use a file path that starts at the directory where scripts are executing but not at...
Read more >
npm WARN tar ENOENT: no such file or directory - MediaWiki
If you already have package-lock.json file just delete it and try again. Reply 7 November 2022 5:29 AM 10 days ...
Read more >
How do you fix error: “ENOENT: no such file or directory, open”
I've even moved everyone from my epidemiology folder to a copy folder and deleted the original folder. The error log still appears on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found