eslint-import-resolver-typescript icon indicating copy to clipboard operation
eslint-import-resolver-typescript copied to clipboard

tsconfig.json "references" is not evaluated

Open DrJume opened this issue 2 years ago • 7 comments

When reading tsconfig.json, it seems to be ignoring the "references" array which includes paths to other tsconfig files in the same directory.

You can reproduce my repo with npm init vue@3 and then add eslint-plugin-import with this resolver.

DrJume avatar Mar 01 '22 15:03 DrJume

Yep, references is not supported yet, and PR welcome to add notice about it or implement this feature.

JounQin avatar Mar 01 '22 16:03 JounQin

My workaround was to include the referenced tsconfigs in the .eslintrc.js with:

module.exports = {
  // ...,
  settings: {
    'import/resolver': {
      typescript: {
        project: [
          __dirname + '/tsconfig.json',
          __dirname + '/tsconfig.other.json',
        ],
      },
    },
  },
}

DrJume avatar Mar 01 '22 16:03 DrJume

My workaround was to include the referenced tsconfigs in the .eslintrc.js with:

module.exports = {
  // ...,
  settings: {
    'import/resolver': {
      typescript: {
        project: [
          __dirname + '/tsconfig.json',
          __dirname + '/tsconfig.other.json',
        ],
      },
    },
  },
}

This didn't seem to solve the problem for me. Any paths defined that are pointing to a reference still don't seem to work, but they work fine if I update their imports to use a relative path instead. Is it possible to see more of your config, or a sample repo?

Would highly appreciate!

psibean avatar Oct 11 '22 08:10 psibean

This didn't seem to solve the problem for me. Any paths defined that are pointing to a reference still don't seem to work, but they work fine if I update their imports to use a relative path instead. Is it possible to see more of your config, or a sample repo?

Or maybe you can provide a reproduction instead.

JounQin avatar Oct 11 '22 08:10 JounQin

This didn't seem to solve the problem for me. Any paths defined that are pointing to a reference still don't seem to work, but they work fine if I update their imports to use a relative path instead. Is it possible to see more of your config, or a sample repo?

Or maybe you can provide a reproduction instead.

Good point!

I should, given I'm the one with the issue, that is on me. I can't put together a full reproduction right now, but here's a breakdown of my config files.

I have a single root tsconfig.json which is only used for linting:

{
  "compilerOptions": {
    "module": "ESNext",
    "target": "es2020",
    "esModuleInterop": true,
    "noImplicitAny": true,
    "moduleResolution": "node",
    "sourceMap": false,
    "baseUrl": ".",
    "strictNullChecks": true,
    "isolatedModules": false,
    "composite": true,
    "removeComments": true,
    "allowSyntheticDefaultImports": true,
    "paths": {
      "@backend/*": ["./backend/src/*"],
      "@client/*": ["./frontend/src"],
      "@app/*": ["./backend/src/app/*"],
      "@shared-types": ["./shared-types/src/*"],
      "*": ["frontend/node_modules/*", "backend/node_modules/*"],
    },
  },
  "include": [
    "./frontend",
    "./backend",
    "./shared-types"
  ],
}

These paths are replicated in ./backend/tsconfig.json, ./frontend/tsconfig.json, and ./shared-types/tsconfig.json.

And my .eslintrc.cjs looks like this:

module.exports = {
  extends: [
    'eslint:recommended',
  ],
  env: {
    browser: true,
    node: true,
  },
  root: true,
  ignorePatterns: [
    ".*",
    "lib/**/*",
  ],
  parserOptions: {
    sourceType: "module",
    ecmaVersion: 2020
  },
  overrides: [
    {
      files: ["**/*.ts"],
      extends: [
        'eslint:recommended',
        'plugin:@typescript-eslint/recommended',
        'plugin:@typescript-eslint/recommended-requiring-type-checking',
      ],
      parser: '@typescript-eslint/parser',
      parserOptions: {
        tsconfigRootDir: __dirname,
        project: [
          './tsconfig.json',
        ],
        EXPERIMENTAL_useSourceOfProjectReferenceRedirect: true
      },
      plugins: ['@typescript-eslint', 'import'],
      settings: {
        "import/parsers": {
          "@typescript-eslint/parser": [".ts", ".tsx"]
        },
        "import/resolver": {
          "typescript": {
            "project": [
              "tsconfig.json",
              __dirname + "/shared-types/tsconfig.json",
              __dirname + "/backend/tsconfig.json",
              __dirname + "/frontend/tsconfig.json"
            ]
          }
        }
      }
    }
  ]
};

psibean avatar Oct 11 '22 08:10 psibean

@psibean Thanks, but you need to provide a minimal but runnable reproduction so that we can help to debug.

JounQin avatar Oct 11 '22 08:10 JounQin