Skip to content

Types break with moduleResolution NodeNext in tsconfig.json #1039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
unshame opened this issue Mar 2, 2023 · 0 comments
Open

Types break with moduleResolution NodeNext in tsconfig.json #1039

unshame opened this issue Mar 2, 2023 · 0 comments

Comments

@unshame
Copy link

unshame commented Mar 2, 2023

With "moduleResolution": "NodeNext" in tsconfig.json, typescript incorrectly assumes the type of exports of smooth-scroll-into-view-if-needed, because it thinks /typings/index defines types for a commonjs module.

This works at runtime but doesn't compile:

import scrollIntoView from 'smooth-scroll-into-view-if-needed';

scrollIntoView(el); // Type 'typeof import("node_modules/smooth-scroll-into-view-if-needed/typings/index")' has no call signatures.

This compiles but breaks at runtime:

import scrollIntoView from 'smooth-scroll-into-view-if-needed';

scrollIntoView.default(el); // TypeError: scrollIntoView.default is not a function

The way I managed to fix it is to patch smooth-scroll-into-view-if-needed's package.json with "type": "module", so typescript knows to treat /typings/index as an es module. But I'm not sure if that's a proper solution, since I'm still trying to wrap my head around this whole typescript node esm disaster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant