ESlint^9 causes an error when importing typescript-eslint with pnpm
Closed this issue · 7 comments
Hello,
I am using eslint-plugin-import with flatConfig.
Even in projects using Yarn, the following warning was displayed:
Could not find a declaration file for module 'eslint-plugin-import'. '/{project_path}/node_modules/eslint-plugin-import/lib/index.js' implicitly has an 'any' type.
But, this issue seems to directly affect the typescript-eslint
package, causing an error in pnpm projects.
I am sharing screenshots and a test repository below.
Even after trying various versions of TypeScript, ESLint, and typescript-eslint, the error consistently occurs only in pnpm projects.
- Despite the error, everything works fine.
I sincerely apologize if I missed a duplicate issue or an existing solution.
Thanks!
That error is a TypeScript error. This package doesn't export its own types, so either you have to install a DT package, or, manually define them yourself.
If the issue is with typescript-eslint, then you've filed this on the wrong repo.
I believe the issue with resolve on typescript-eslint
is that the package doesn't have a main
and exclusively leverages export conditions, which the node resolver doesn't currently support.
As far as types go, weren't those added recently? I thought I saw @G-Rath putting that in. https://github.com/import-js/eslint-plugin-import/blob/main/index.d.ts
@michaelfaith
Oh, I hadn't checked index.d.ts
before. I was considering contributing to the DefinitelyTyped.. 🥲
Then It seems that the current issue is index.d.ts
is not being properly exported.
Even in a Yarn package, type warnings appeared. As a temporary workaround, I handled it like this, and the warnings no longer showed up:
import { ESLint, Linter } from "eslint";
declare const eslintPluginImport: ESLint.Plugin & {
configs: {
recommended: Linter.LegacyConfig;
errors: Linter.LegacyConfig;
warnings: Linter.LegacyConfig;
typescript: Linter.LegacyConfig;
};
flatConfigs: {
recommended: Linter.Config;
};
};
export = eslintPluginImport;
Ah, it looks like the types change hasn't been released yet. Merged but not in a release. So, you should be able to remove that workaround after the release is cut: https://github.com/import-js/eslint-plugin-import/blob/main/CHANGELOG.md#unreleased
Thank you for your help!
But another problem remains: The error persists only in pnpm projects on the line import tseslint from "typescript-eslint"
, and seems to be influenced by importing eslint-plugin-import
. (This error persists even after I created a index.d.ts
file.)
I don’t believe this is an issue with typescript-eslint
.
Could it be something I misconfigured? Or, if this is an issue caused by pnpm's symbolic links, how can it be resolved?
If you're importing typescript-eslint, that's where the problem lies.
I found the exact cause today.
When using the tseslint.config()
function from eslint-typescript
, eslint-plugin-import
must be declared inside extends
array rather than being declared parameter.
import tseslint from "typescript-eslint"
import importPlugin from "eslint-plugin-import"
export default tseslint.config(
// other configs...
...
- importPlugin.flatConfigs.recommended,
+ {
+ files: ["**/*.{ts,tsx}"],
+ extends: [importPlugin.flatConfigs.recommended],
+ // other configs...
+ }
The kind of package manager didn't matter.