This problem seems straightforward, but finding a solution has been tricky...
Whenever I try to use @typescript-eslint/utils, I encounter the error message
Cannot find module @typescript-eslint/utils or its corresponding type declarations
.
Here is the structure of the project:
.
├── packages/
│ └── eslint-plugin-foo/
│ ├── node_modules/
│ │ └── @typescript-eslint/
│ │ └── utils
│ ├── src/
│ │ └── rules/
│ │ └── some-rule.ts
│ └── tsconfig.json
└── tsconfig.json
In the file some-rule.ts,
the package is being imported like this:
// some-rule.ts
// error: Cannot find module @typescript-eslint/utils or its corresponding type declarations. ts(2307)
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
~~~~~~~~~~~~~~~~~~~~~~~~
...
Here is the structure of the package:
.
└── node_modules/
└── @typescript-eslint/
└── utils/
├── dist/
│ ├── index.d.ts
│ ├── index.js
│ └── ...
└── package.json
Below is the package.json
of @typescript-eslint/utils
:
{
"name": "@typescript-eslint/utils",
"version": "6.8.0",
"files": [
"dist",
"_ts4.3",
"package.json",
"README.md",
"LICENSE"
],
"type": "commonjs",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./ast-utils": {
"types": "./dist/ast-utils/index.d.ts",
"default": "./dist/ast-utils/index.js"
},
...
},
"dependencies": {
"@eslint-community/eslint-utils": "^4.4.0",
...
},
...
}
After changing the import to @typescript-eslint/utils/dist
, the initial error disappears. However, a new error appears when running the test:
Package subpath './dist' is not defined by "exports" in somepath/packages/eslint-plugin-foo/node_modules/@typescript-eslint/utils/package.json
How can I go about resolving this issue?