Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Issue Description
I'm using typescript-eslint
in conjunction with eslint-plugin-import
. I've migrated to the new flat eslint config format. Here is a minimal reproduction of my issue:
import js from '@eslint/js'
import typescriptPlugin from '@typescript-eslint/eslint-plugin'
import typescriptParser from '@typescript-eslint/parser'
import importPlugin from 'eslint-plugin-import'
export default [
js.configs.recommended,
{
files: ['**/*.@(js|ts|jsx|tsx)'],
plugins: { import: importPlugin },
rules: {
...importPlugin.configs.recommended.rules,
},
},
{
files: ['**/*.@(ts|tsx)'],
languageOptions: {
parser: typescriptParser,
parserOptions: {
sourceType: 'module',
project: './tsconfig.eslint.json',
},
},
settings: {
...importPlugin.configs.typescript.settings,
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx', '.mts', '.cts'],
},
},
plugins: {
'@typescript-eslint': typescriptPlugin,
import: importPlugin,
},
rules: {
...typescriptPlugin.configs.recommended.rules,
...typescriptPlugin.configs.strict.rules,
...importPlugin.configs.recommended.rules,
...importPlugin.configs.typescript.rules,
},
},
]
Naturally, I run eslint on the eslint.config.js
file itself, which gives the following errors:
ts-eslint-import-bug/eslint.config.js
2:30 error Unable to resolve path to module '@typescript-eslint/eslint-plugin' import/no-unresolved
3:30 error Unable to resolve path to module '@typescript-eslint/parser' import/no-unresolved
✖ 2 problems (2 errors, 0 warnings)
This wasn't happening pre-6.0 - importing these modules worked without any issue.
I think the underlying issue is import-js/eslint-plugin-import#2132 and import-js/eslint-plugin-import#2703. It seems that starting in v6.0 of this repo, there is no longer a main
field in package.json
.
I tested my theory by manually adding "main": "./dist/index.js"
to node_modules/@typescript-eslint/parser/package.json
and node_modules/@typescript-eslint/eslint-plugin/package.json
, and this resolved the eslint errors.
It seems this is also semi-related to #7300, wherein it was decided to not re-add the main
field to package.json
. Perhaps my issue can act as another data point supporting re-adding it?
Disclaimer: I understand that this is not a "bug" in typescript-eslint
. Hopefully support for exports
will come to eslint-plugin-import
, but until then, it seems like this issue could be more easily be resolved here? (Would @ljharb like to chime in?)
Reproduction Repository Link
https://github.com/b0o/ts-eslint-import-bug
Repro Steps
- clone the repo
npm install
eslint eslint.config.js
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
6.5.0 |
@typescript-eslint/parser |
6.5.0 |
eslint-plugin-import |
2.28.1 |
TypeScript |
5.2.2 |
ESLint |
8.48.0 |
node |
20.5.1 |