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

paths in tsconfig.json breaks import/no-extraneous-dependencies #2617

Open
haven2world opened this issue Dec 16, 2022 · 5 comments
Open

paths in tsconfig.json breaks import/no-extraneous-dependencies #2617

haven2world opened this issue Dec 16, 2022 · 5 comments

Comments

@haven2world
Copy link

Our project is a mono repo managed by Nx. All dependencies are installed at the root directory and the package.json containing all dependencies is also there.
When I import logger in another repo, the rule import/no-extraneous-dependencies fails.

The directory structure would be like:

.
├── node_modules
├── libs
│   ├── logger
│   │   ├── package.json
│   │   ├── src
│   │   ├── tsconfig.json
│   │ 
│   └── another-lib
│       ├── package.json
│       ├── src
│       ├── tsconfig.json
├── package.json
├── .eslintrc.js
├── tsconfig.base.json

.eslintrc.js:

module. Exports = {
...
settings: {
    'import/resolver': {
      typescript: {
        project: 'tsconfig.base.json',
      },
      node: {
        extensions: ['.js', '.jsx', '.ts', '.tsx'],
      },
    },
},
rules: {
...
        'import/no-extraneous-dependencies': [
          'error',
          {
            devDependencies: [
              '**/__tests__/**', // jest pattern
            ],
            optionalDependencies: false,
            peerDependencies: false,
            packageDir: './',
          },
        ],
...
}
}

tsconfig.base.json:

"paths": {
      "@my/logger": [
        "libs/logger/src/index.ts"
      ],
      "@my/another-lib": [
        "libs/another-lib/src/index.ts"
      ]
}

package.json in root directory is a normal one:

{
  "name": "my",
  "version": "0.0.0",
  "private": true,
  "scripts": {
...
  },
"dependencies": {
...
  },
  "devDependencies": {
...
  },
...
}

package.json in libs is really simple:

{
  "name": "@my/another-libr",
  "version": "0.0.1",
  "type": "commonjs"
}

tsconfig.json in libs will extends the base one.

And when I import logger from "@my/logger" in another-lib, this rule will fail

  4:1  error  '@my/logger' should be listed in the project's dependencies. Run 'npm i -S @olm/logger' to add it  import/no-extraneous-dependencies
@haven2world
Copy link
Author

I found it could be fixed by import/internal-regex, set the @my/logger as internal package and this issue can be fixed.

@ljharb ljharb closed this as not planned Won't fix, can't repro, duplicate, stale Mar 2, 2023
@SimonCockx
Copy link

SimonCockx commented Mar 2, 2023

@haven2world This is a workaround, not a fix, right? This plugin should consider the paths property.

I think this issue should remain open.

@haven2world
Copy link
Author

@SimonCockx TBH, I have no idea. Since in the doc, it says we can use import/internal-regex to mark package as internal in mono repo. I'm not sure if this is by design.

@SimonCockx
Copy link

SimonCockx commented Mar 2, 2023

Still, an nx repo can have hundreds of these, so making sure that the paths variable and internal-regex are in sync just seems unnecessary maintenance.

Maybe @ljharb can give us a bit of context?

@ljharb
Copy link
Member

ljharb commented Mar 2, 2023

That seems a reasonable enhancement, yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants