Skip to content

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

Open
@haven2world

Description

@haven2world

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions