smooth-scroll-into-view-if-needed
smooth-scroll-into-view-if-needed copied to clipboard
Types break with moduleResolution NodeNext in tsconfig.json
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.