Skip to content

createTypeScriptImportResolver ignores options #341

Closed
@carlocorradini

Description

@carlocorradini

I can't figure out how createTypeScriptImportResolver handles options.
I'm using eslint-plugin-import-x in conjunction with eslint-import-resolver-typescript in a monorepo.

eslint.config.ts:

export default tseslint.config(
  {
    settings: {
      "import/resolver-next": [
        createTypeScriptImportResolver({
          alwaysTryTypes: true,
          project: ["packages/*/tsconfig.json"],
        }),
      ],
    },
  }
);

I have a simple TypeScript path that points to the src directory:

{
  "compilerOptions": {
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

Even though I've configured createTypeScriptImportResolver and tsconfig.json with the project field, it appears that it's ignored, and I get the following error:

error  Unable to resolve path to module '@/example.js'  import-x/no-unresolved

I've tried to debug and discovered that in the implementation of createTypeScriptImportResolver, the returned resolve function (the one with two parameters) is never called (try adding a simple console.log(...)) and only the "global" resolve (the one with four parameters) is called always with the options parameter set to undefined:

  // ...
  return {
    interfaceVersion: 3,
    name: IMPORTER_NAME,
    resolve(source: string, file: string) {
      console.log(`options: ${options}`); // NEVER CALLED
      return resolve(source, file, options, resolver)
    },
  }

Furthermore, the current working directory is the only project I've seen (in global resolve).
The latter implies that the resolution of paths defined in the tsconfig.json in the current working directory (where npx eslint . is called) simply works since the algorithm correctly detects the paths defined in the tsconfig.json (but not for custom project).

Therefore, this issue relates to custom tsconfig or monorepos only.

I'm willing to help, even if I'm not sure how much I can contribute.

PS: I hope this is due to a misconfiguration, but I've tried numerous times following the documentation and attempting to catch the console.log message, but without success.

PSPS: Sorry for the long message... Apologize

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions