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

This bug is already described here https://github.com/nrwl/nx/issues/3370 and recently, there has been a request to have it re-opened but seems still not.

The present ticket was opened in the hope that this will be fixed once and for all. Indeed, this bug is detrimental to the developer’s workflow. Therefore, questioning the use of NX. The next information in this ticket is mostly repeated from https://github.com/nrwl/nx/issues/3370.

Note

In my case, it was resolved after making sure that the nx root folder was the git root folder.

Not working:

project
     - .git/
     - nx folder
     - documentation
     - security
     - ...

Working:

project
     - nx folder
        - .git/
        - documentation
        - security
        - ...

However, there is a need for the sub-folder structure for other developers and sometimes, it is not possible to change the folder structure. In addition, the different mentioned work arounds (git stash, git -ma) are not considered the proper solutions as NX should correctly handle the deleted, renamed or moved files.

Current Behavior

After deleting any file in the repository there is an error with yarn start (also with other “affected” commands such as yarn affected:lint, yarn affected:test)

“Error: ENOENT: no such file or directory {{old location of the file}}”.

Note

This is also affecting the components importing those files as well as modification to the files itself in some cases (!). It is not related to NX cache but rather this https://github.com/nrwl/nx/issues/3370#issuecomment-858391601

Expected Behavior

Should not be an error after file is removed in case it is not used in project source locally. It also happens when renaming or moving any file around.

Steps to Reproduce

  1. create new workspace via npx create-nx-workspace@latest with Angular or React app
  2. run yarn start or affected:lint
  3. delete any component (eg. app.component.spec.ts)
  4. run yarn start or affected:lint again
  5. get error message

Failure logs

Error: ENOENT: no such file or directory, open {{old location of the file}} at Object.openSync (fs.js:458:3) at Object.readFileSync (fs.js:360:35) [...]

Environment

macOS Big Sur 11.2.3
git version 2.30.1
"@nrwl/cli": "12.5.8",
"@nrwl/cypress": "12.5.8",
"@nrwl/eslint-plugin-nx": "12.5.8",
"@nrwl/express": "12.5.8",
"@nrwl/jest": "12.5.8",
"@nrwl/linter": "12.5.8",
"@nrwl/next": "12.5.8",
"@nrwl/node": "12.5.8",
"@nrwl/react": "12.5.8",
"@nrwl/storybook": "12.5.8",
"@nrwl/tao": "12.5.8",
"@nrwl/web": "12.5.8",
"@nrwl/workspace": "12.5.8",
"typescript": "~4.3.5",
"next": "11.0.1",
"react": "17.0.2",

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 27
  • Comments: 51 (1 by maintainers)

Most upvoted comments

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! 🙏

Bump. This issue is very annoying. I do not want to be forced to commit after renaming/moving files.

@FrozenPandaz Could you remove the bot action for this issue? I don’t mind it might take a long time to fix this issue.

I can understand it is not the priority. However, it is just annoy to keep the bot away by making more useless comments, including this one.

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! 🙏

Same issue on v12.9.0

@pavandv you don’t have to commit to get rid of this error. Just do git stash and git stash pop

Definitely shouldn’t be closed - I ran into this yesterday.

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! 🙏

@maxisam a fix would be better than a work around.

Hey thanks for reopening this. I have created the first issue for this bug https://github.com/nrwl/nx/issues/3370 , which is closed now. But I retrieve email notifications from github that people still facing this almost each day.

Originally we have aborted using nx because of this annoying issue. Now in my new angular and nest.js proj I would like to try NX again, but I do not understand why this bug is ignored for so long time by Nx team.

I consider the tool/product really cool. But do not understand why such an annoying thing is not fixed for so long

Le Bump

Just a friendly reminder, that this issue should not be closed.

Thank you!

@FrozenPandaz, I was able to reproduce the issue using your repo.

Steps (all commands are run from the nx-workspace folder):

  1. Generate a new dummy component: nx g component --name=TestComponent --export=false
  2. Run tests & lint: nx test && nx lint.
  3. Stage the changes and commit. git add . && git commit -m "Adds TestComponent"
  4. Rename the app component & fix the imports so that the project builds correctly:
renamed:    apps/app1/src/app/app.module.css -> apps/app1/src/app/app-1.module.css
renamed:    apps/app1/src/app/app.spec.tsx -> apps/app1/src/app/app-1.spec.tsx
renamed:    apps/app1/src/app/app.tsx -> apps/app1/src/app/app-1.tsx
  1. Stage the changes: git add .
  2. Run nx test:
(node:75939) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open 'git/nx-examples/nx-workspace/apps/app1/src/app/app.spec.tsx'
    at Object.openSync (fs.js:476:3)
    at Object.readFileSync (fs.js:377:35)
    at Object.defaultFileRead (git/nx-examples/nx-workspace/node_modules/@nrwl/workspace/src/core/file-utils.js:161:17)
    at TypeScriptImportLocator.fromFile (git/nx-examples/nx-workspace/node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/typescript-import-locator.js:22:38)
    at git/nx-examples/nx-workspace/node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/explicit-project-dependencies.js:11:27
    at Array.forEach (<anonymous>)
    at git/nx-examples/nx-workspace/node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/explicit-project-dependencies.js:10:51
    at Array.forEach (<anonymous>)
    at Object.buildExplicitTypeScriptDependencies (git/nx-examples/nx-workspace/node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/explicit-project-dependencies.js:9:37)
    at buildProjectGraph (git/nx-examples/nx-workspace/node_modules/@nrwl/workspace/src/core/project-graph/project-graph.js:103:26)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:75939) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:75939) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

just for the sake of helping someone out if you are still having issues with this:

https://github.com/nrwl/nx/issues/3370#issuecomment-1261391072

@evgeny-kirichuk Commit the changes. That works for me.

I’ve just faced the issue while trying to build the app. Stash - stash pop doesn’t help. What are the options in such a case? I just can’t build the app anymore.

To all subscribers of this issue: there seems to be progress in #7177 which is another clone of the originating issue.

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! 🙏

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! 🙏

image

Seriously, we are adding to global warming by making this kinda useless post just for the bot

Any comment on this issue NX creators/maintainers? This issue seems just ignored lol.

@vsavkin @FrozenPandaz

have the same issue with “@nrwl/workspace”: “12.7.2”

I’m also facing this after renaming a folder and running a build executor. I use @nrwl/workspace@12.3.4 and here is the stack trace:

Error: ENOENT: no such file or directory, open '***/index.spec.ts'
    at Object.openSync (fs.js:476:3)
    at Object.readFileSync (fs.js:377:35)
    at Object.defaultFileRead (***/node_modules/@nrwl/workspace/src/core/file-utils.js:160:17)
    at TypeScriptImportLocator.fromFile (***/node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/typescript-import-locator.js:22:38)
    at ***/node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/explicit-project-dependencies.js:11:27
    at Array.forEach (<anonymous>)
    at ***/node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/explicit-project-dependencies.js:10:44
    at Array.forEach (<anonymous>)
    at buildExplicitTypeScriptDependencies (***/node_modules/@nrwl/workspace/src/core/project-graph/build-dependencies/explicit-project-dependencies.js:9:30)
    at ***/node_modules/@nrwl/workspace/src/core/project-graph/project-graph.js:72:41 {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '***/index.spec.ts'
}

Running the command with --skip-nx-cache does not fix the issue as well as removing node_modules/.cache/nx cache folder.