Skip to content

Types break with moduleResolution NodeNext in tsconfig.json #1039

@unshame

Description

@unshame

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions