-
Notifications
You must be signed in to change notification settings - Fork 49.6k
Description
When package.json has "type": "module"
and tsconfig.json has "module": "nodenext"
, typescript thinks that reactHooks.configs
is undefined.
Steps To Reproduce
package.json:
{
"type": "module",
"dependencies": {
"eslint-plugin-react-hooks": "^7.0.0",
"typescript": "^5.9.3"
}
}
tsconfig.json:
{
"compilerOptions": {
"module": "nodenext",
}
}
index.ts:
import reactHooks from "eslint-plugin-react-hooks";
console.log(reactHooks.default); // ts thinks this is a real field, but it's not
console.log(reactHooks.configs); // ts thinks this isn't a real field, but it is
The error is:
Property 'configs' does not exist on type 'typeof import("<path_to_repo>/node_modules/eslint-plugin-react-hooks/index")'.
I don't really understand what's going on here, but the types worked fine with my project in 5.2.0
- I didn't try any 6.x
versions. The types are fine if either of the settings in package.json
or tsconfig.json
are removed, and TS is able to resolve a more concrete type than the strange typeof import
thing that shows up here.
Link to code example:
https://github.com/skondrashov/borked-react-hooks-type
git clone https://github.com/skondrashov/borked-react-hooks-type; cd borked-react-hooks-type; npm i; npx tsc
The current behavior
Error trying to access reactHooks.configs
, no error trying to access reactHooks.default
.
The expected behavior
No error trying to access reactHooks.configs
, error trying to access reactHooks.default
.