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

[import/no-unresolved] when importing from another package in a monorepo

Open tpluscode opened this issue 1 year ago • 6 comments

Specifically, I have a package with an export map like this

{
  "name": "@hydrofoil/roadshow-ng",
  "exports": {
    ".": "./index.js",
    "./rs-view.js": "./rs-view.js",
    "./viewers.js": "./viewers.js"
  }
}

In other packages I import '@hydrofoil/roadshow-ng/rs-view.js' etc. This gets reported as unresolved.

Interestingly, if I drop the extension or change to .ts, the import plugin no longer complains...

tpluscode avatar Jan 30 '23 18:01 tpluscode

Anyone?

tpluscode avatar Mar 26 '23 10:03 tpluscode

Hi. This fixed a similar issue for me. I didn't need to add a exports entry to my package.json files though.

I fixed my issue by adding this to my eslint.cjs file in the root of my monorepo:

    parserOptions: {
        project: ['tsconfig.json', 'packages/*/tsconfig.json'],
        node: true,
    },
    settings: {
        'import/parsers': {
            '@typescript-eslint/parser': ['.ts'],
        },
        'import/resolver': {
            typescript: {
                // See https://github.com/import-js/eslint-import-resolver-typescript for documentation of these settings
                // This `project` entry is needed, in addition to the `project` entry above under `parserOptions`,
                // otherwise eslint-plugin-import's `import/no-unused-modules` rule will not work correctly
                project: ['tsconfig.json', 'packages/*/tsconfig.json'],
            },
        },
    },

simondean avatar Apr 14 '23 17:04 simondean

@tpluscode Sorry I'm very late here, can you please provide an online runnable reproduction?

JounQin avatar Dec 06 '23 15:12 JounQin

@JounQin: https://github.com/tminuscode/resolver-typescript-package-exports

tpluscode avatar Dec 06 '23 21:12 tpluscode

Have you had a chance to to look into it @JounQin \

tpluscode avatar Mar 26 '24 09:03 tpluscode

See #275 and https://github.com/webpack/enhanced-resolve/issues/413

JounQin avatar Mar 26 '24 10:03 JounQin