Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'ENOENT: no such file or directory' error when linting a non-empty import that violates @nrwl/nx/enforce-module-boundaries #15207

Closed
jarodburchill opened this issue Feb 23, 2023 · 2 comments · Fixed by #15345
Assignees
Labels
outdated scope: linter Issues related to Eslint support in Nx type: bug

Comments

@jarodburchill
Copy link

Current Behavior

The follow error occurs when violating import is not empty:

 >  NX   ENOENT: no such file or directory, open '/Users/jarod.burchill/GitHub/nx-lint-issue-example/libs/shared/src/lib/shared/index.ts'

   Occurred while linting /Users/jarod.burchill/GitHub/nx-lint-issue-example/libs/shared/src/lib/test.tsx:1
   Rule: "@nrwl/nx/enforce-module-boundaries"
   Pass --verbose to see the stacktrace.

Works as expected when the violating import is empty though:

Linting "shared"...

/Users/jarod.burchill/GitHub/nx-lint-issue-example/libs/shared/src/lib/test.tsx
  1:1  error  Projects should use relative imports to import from other files within the same project. Use "./path/to/file" instead of import from "@nx-lint-issue-example/shared"  @nrwl/nx/enforce-module-boundaries

✖ 1 problem (1 error, 0 warnings)

Lint errors found in the listed files.

Expected Behavior

The import being non-empty should not cause the linter to crash and give a ENOENT: no such file or directory error

GitHub Repo

https://github.com/jarodburchill/nx-lint-issue-example

Steps to Reproduce

Setup (can skip if using provided repo):

  1. npx create-nx-workspace@15.8.0-beta.4 nx-lint-issue-example --preset=react-monorepo --appName=myapp --bundler=vite --style=css --nxCloud=false
  2. cd nx-lint-issue-example
  3. npx nx generate @nrwl/react:library shared --unitTestRunner=none --bundler=none
  4. touch libs/shared/src/lib/test.tsx
  5. Add the following to test.tsx:
import {  } from "@nx-lint-issue-example/shared";

export const Test = () => {
  return (
    <div>Test</div>
  )
}

Run linter with an empty import statement:

  1. npx nx lint shared
  2. NOTE: the output is the following (expected):
> nx run shared:lint


Linting "shared"...

/Users/jarod.burchill/GitHub/nx-lint-issue-example/libs/shared/src/lib/test.tsx
  1:1  error  Projects should use relative imports to import from other files within the same project. Use "./path/to/file" instead of import from "@nx-lint-issue-example/shared"  @nrwl/nx/enforce-module-boundaries

✖ 1 problem (1 error, 0 warnings)

Lint errors found in the listed files.


 —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  NX   Ran target lint for project shared (867ms)
 
    ✖    1/1 failed
    ✔    0/1 succeeded [0 read from cache]

Run linter with a non-empty import statement:

  1. Change the import statement in test.tsx:
-  import {  } from "@nx-lint-issue-example/shared";
+  import { Shared } from "@nx-lint-issue-example/shared";
  1. npx nx lint shared
  2. NOTE: the output is the following (unexpected, should give same @nrwl/nx/enforce-module-boundaries error as it did when the import statement was empty):
> nx run shared:lint


Linting "shared"...

 >  NX   ENOENT: no such file or directory, open '/Users/jarod.burchill/GitHub/nx-lint-issue-example/libs/shared/src/lib/shared/index.ts'

   Occurred while linting /Users/jarod.burchill/GitHub/nx-lint-issue-example/libs/shared/src/lib/test.tsx:1
   Rule: "@nrwl/nx/enforce-module-boundaries"
   Pass --verbose to see the stacktrace.


 —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  NX   Ran target lint for project shared (846ms)
 
    ✖    1/1 failed
    ✔    0/1 succeeded [0 read from cache]

Nx Report

Node : 18.12.1
   OS   : darwin arm64
   npm  : 8.19.2
   
   nx                      : 15.8.0-beta.4
   @nrwl/linter            : 15.8.0-beta.4
   @nrwl/workspace         : 15.8.0-beta.4
   @nrwl/cli               : 15.8.0-beta.4
   @nrwl/cypress           : 15.8.0-beta.4
   @nrwl/devkit            : 15.8.0-beta.4
   @nrwl/eslint-plugin-nx  : 15.8.0-beta.4
   @nrwl/js                : 15.8.0-beta.4
   @nrwl/react             : 15.8.0-beta.4
   @nrwl/tao               : 15.8.0-beta.4
   @nrwl/vite              : 15.8.0-beta.4
   typescript              : 4.9.5

Failure Logs

> nx run shared:lint


Linting "shared"...

 >  NX   ENOENT: no such file or directory, open '/Users/jarod.burchill/GitHub/nx-lint-issue-example/libs/shared/src/lib/shared/index.ts'

   Occurred while linting /Users/jarod.burchill/GitHub/nx-lint-issue-example/libs/shared/src/lib/test.tsx:1
   Rule: "@nrwl/nx/enforce-module-boundaries"
   Pass --verbose to see the stacktrace.


 —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  NX   Ran target lint for project shared (846ms)
 
    ✖    1/1 failed
    ✔    0/1 succeeded [0 read from cache]

Additional Information

No response

@AgentEnder AgentEnder added the scope: linter Issues related to Eslint support in Nx label Feb 24, 2023
@meeroslav meeroslav self-assigned this Feb 27, 2023
@meeroslav
Copy link
Contributor

Good catch @jarodburchill! Thank you for reporting this.

I will make a fix right away.

@github-actions
Copy link

github-actions bot commented Apr 1, 2023

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: linter Issues related to Eslint support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants