Skip to content

TypeScript types are broken when using node10 moduleResolution #337

@TrevorBurnham

Description

@TrevorBurnham

After upgrading my Next.js app to superjson@2.2.5, I get this tsc error:

src/fetch.tsx:3:23 - error TS7016: Could not find a declaration file for module 'superjson'. '/my-project-dir/node_modules/superjson/dist/index.js' implicitly has an 'any' type.
  There are types at '/my-project-dir/node_modules/superjson/dist/index.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

3 import superJSON from "superjson";
                        ~~~~~~~~~~~

The invaluable arethetypeswrong checker confirms the issue:

$ npx @arethetypeswrong/cli --from-npm superjson@2.2.5

❌ Import resolved to JavaScript files, but no type declarations were found. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/UntypedResolution.md


┌───────────────────┬─────────────┐
│                   │ "superjson" │
├───────────────────┼─────────────┤
│ node10            │ ❌ No types │
├───────────────────┼─────────────┤
│ node16 (from CJS) │ 🟢 (CJS)    │
├───────────────────┼─────────────┤
│ node16 (from ESM) │ 🟢 (ESM)    │
├───────────────────┼─────────────┤
│ bundler           │ 🟢          │
└───────────────────┴─────────────┘

Compare to 2.2.3:

$ npx @arethetypeswrong/cli --from-npm superjson@2.2.3

❌ Import resolved to JavaScript files, but no type declarations were found. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/UntypedResolution.md


┌───────────────────┬─────────────┐
│                   │ "superjson" │
├───────────────────┼─────────────┤
│ node10            │ 🟢          │
├───────────────────┼─────────────┤
│ node16 (from CJS) │ ❌ No types │
├───────────────────┼─────────────┤
│ node16 (from ESM) │ 🟢 (ESM)    │
├───────────────────┼─────────────┤
│ bundler           │ 🟢          │
└───────────────────┴─────────────┘

So recent changes fixed one type issue, but broke existing types.

It's worth noting that "moduleResolution": "node10" is the default, and is effectively required by Next.js (it overwrites the moduleResolution value in tsconfig.json if you change it to something else). So it's safe to say that this type issue affects a large number of superjson consumers.

Relatedly, I sent a PR a while back to use tsup to build the correct types for all moduleResolution modes: #327

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