Closed
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.
Relevant Package
rule-tester
Repro Code
Try to compile an ESLint plugin project with this code and `skipLibCheck: false` in **tsconfig.json**:
import { RuleTester } from '@typescript-eslint/rule-tester';
Expected Result
The code should compile without errors.
Actual Result
tsc
reports a build failure like this:
../../common/temp/node_modules/.pnpm/@typescript-eslint+rule-tester@6.19.0_@eslint+eslintrc@3.0.0_eslint@8.7.0_typescript@5.3.3/node_modules
/@typescript-eslint/rule-tester/dist/types
/DependencyConstraint.d.ts:1:35 - error TS7016: Could not find a declaration file for module 'semver'. 'C:/Git/rushstack/common/temp/node_modules/.pnpm/semver@7.5.4/node_modules/semver/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/semver` if it exists or add a new declaration (.d.ts) file containing `declare module 'semver';`
1 import type { RangeOptions } from 'semver';
~~~~~~~~
Found 1 error in ../../common/temp/node_modules/.pnpm/@typescript-eslint+rule-tester@6.19.0_@eslint+eslintrc@3.0.0_eslint@8.7.0_typescript@5.3.3/node_modules/@typescript-eslint/rule-tester/dist/types/DependencyConstraint.d.ts:1
The problem is caused by this code:
It imports types from "semver"
, but that dependency is not declared in package.json.
Using an old-fashioned installation model such as NPM or Yarn Classic, then the semver
package will likely get "hoisted" allowing the compiler to load typings from a semver
folder installed to satisfy some other unrelated package. However with a modern installation model such as Yarn Plug'n'Play or PNPM, the import will fail; this is more correct behavior, because dependency versions should be explicitly specified rather than fished out of a node_modules folder with no idea what version you will get.
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
6.19.0 |
TypeScript |
5.3.3 |