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

[import/no-unresolved] not working in our mono-repo from 2.0.0 #37

Closed
rheaditi opened this issue Nov 28, 2019 · 7 comments
Closed

[import/no-unresolved] not working in our mono-repo from 2.0.0 #37

rheaditi opened this issue Nov 28, 2019 · 7 comments

Comments

@rheaditi
Copy link

We recently upgraded to Typescript 3.7 and updated all eslint + prettier related packages. Moving from eslint-import-resolver-typescript@1.1.1 to eslint-import-resolver-typescript@2.0.0 is leading to more import/no-unresolved errors showing up for paths configured in tsconfig.json in the sub-packages.

Our structure

.
├── ...
├── .eslintrc.js
├── packages
│   ├── a
│   │   ├── .eslintrc.js
│   │   ├── tsconfig.json
│   │   └── package.json
│   └── b
│       ├── .eslintrc.js
│       ├── tsconfig.json
│       └── package.json
├── ...
├── package.json
├── lerna.json

We're using multiple .eslintrc.js in each directory since the projects are cross platform (node/browser) and have different environments & configurations.

Configs

// .eslintrc.js
module.exports = {
  // ...
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: 'module',
  },
  plugins: ['import'],
  rules: {
    // ...
    /** Show errors for un-resolved imports */
    'import/no-unresolved': 'error',
    // ...
  },
  settings: {
    'import/parsers': {
      '@typescript-eslint/parser': ['.ts', '.tsx'],
    },
    'import/resolver': {
      typescript: {
        directory: ['packages/*/tsconfig.json'],
      },
    },
  },
};
// .eslintrc.js
const { resolve } = require('path');

module.exports = {
  settings: {
    'import/resolver': {
      typescript: {
        directory: resolve(__dirname, 'tsconfig.json'),
      },
    },
  },
};

What we've tried

  • Having a single setting in the root level with packages/*/tsconfig.json
  • Having a single setting in the root level with array of actual file paths to the tsconfig directory.
  • Both the above with explicit setting in the package (a/b) level setting with directory: resolve(__dirname, 'tsconfig.json'),

We downgraded back to v1.1.1. 😅

Can you help us out? Happy to provide more information as required.

@JounQin
Copy link
Collaborator

JounQin commented Nov 28, 2019

Please provide a minimal runnable reproduction, thx.

@JounQin
Copy link
Collaborator

JounQin commented Nov 28, 2019

Personal idea without approve, you should never use multiple .eslintrc.js files, replace them with overrides instead.

Take https://github.com/1stG/configs/tree/master/packages/eslint-config as an example.

Feel free to point out if I'm wrong.

@JounQin
Copy link
Collaborator

JounQin commented Nov 28, 2019

Or try to add root: true in every .eslintrc.js so that the root level eslint will not try to resolve paths any more.

@kurnev
Copy link

kurnev commented Dec 5, 2019

I have possibly encountered the same problem:

Whenever you run eslint on several files from different sub-packages import-unresolved errors show up, but running on single file is always OK.

Please check this repo for reproduction: https://github.com/ZmoNkk/import-resolver-typescript-demo

Repro steps:

  1. Install eslint and all dependencies
  2. Run ./node_modules/.bin/eslint a/index.ts.
  3. As expected it shows only one error regarding non existing package.
  4. Run ./node_modules/.bin/eslint --ext .ts ./

Result:

First file is linted ok, but second file throws import/no-unresolved error on exising package.

Any advice? Possibly this is a misconfiguration on my part, but I have tried different setups and this issue persists.

Issue does not appear on v1.1.1 as well

@JounQin
Copy link
Collaborator

JounQin commented Dec 7, 2019

@ZmoNkk Thx for reproduction, I'll check it ASAP when I'm not so busy.

@JounQin
Copy link
Collaborator

JounQin commented Dec 8, 2019

@rheaditi @ZmoNkk Please check https://github.com/ZmoNkk/import-resolver-typescript-demo/pull/1/files. I believe you're both misusing eslint with eslint-import-resolver-typescript.

I'm going close this issue temporarily, feel free to point out if I'm wrong and I'll reopen it.

@towry
Copy link

towry commented Nov 22, 2022

I have below config in .eslintrc.yml and the vscode + volar give me following error:

config:

parserOptions:
  ecmaVersion: latest
  parser: '@typescript-eslint/parser'
  sourceType: module
  createDefaultProgram: true
  project:
    - ./tsconfig.json

error:

Parsing error: Cannot read file '/users/xxx/workspace/monorepo-proj/tsconfig.json'

And the project folder structure is:

--- monorepo-proj
   --- apps/demo
         --- apps/demo/.eslintrc.yml

if I change ./tsconfig.json to apps/demo/tsconfig.json, the can not read file error is gone, but another bunch errors appears.

I have to use apps/demo/<some-path-in-project> every where in the .eslintrc.yml file.

So the question become: how to resolve this? Because if I want to run the app outside of monorepo, it will not work again.

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

No branches or pull requests

4 participants