Skip to content

Conversation

@TrevorBurnham
Copy link

This PR updates the build configuration to make the types compatible with all consumers. To achieve that, it uses tsup.

In order to use tsup, I had to upgrade TypeScript. That produced warnings from the lint configuration in tsdx, so I ugraded the lint configuration as well. Since tsdx hasn't had a release since 2020, that meant replacing it. I've tried to keep the ESLint config as similar as possible to the old one, but there are some small changes. All of the changes to files in src/ are autofix changes from the newer ESLint and Prettier.

This change should be fully backward-compatible, except for any consumers who were explicitly importing from /dist-cjs. Searching GitHub, I found no instances of that pattern.

Before

$ npx --yes @arethetypeswrong/cli --pack 

❌ 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           │ 🟢          │
└───────────────────┴─────────────┘

After

$ npx --yes @arethetypeswrong/cli --pack

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

@TrevorBurnham TrevorBurnham requested a review from Skn0tt as a code owner August 31, 2025 02:37
@Skn0tt
Copy link
Collaborator

Skn0tt commented Sep 1, 2025

Could you start by explaining what's the issue you're trying to fix?

@TrevorBurnham
Copy link
Author

Sure. Let's say that you create a CommonJS package with a dependency on superjson and a tsconfig.json like this:

{
  "compilerOptions": {
    "module": "node16",
    "moduleResolution": "node16",
    "target": "es2021"
  }
}

Trying to run tsc will trigger this error:

error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("superjson")' call instead.
  To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to '/Users/trevor.burnham/code/superjson/superjson-ts-error-demo/package.json'.

1 import { SuperJSON } from 'superjson';
                            ~~~~~~~~~~~

I've found that it's very difficult to build types in a way that satisfies all possible consumers with just tsc, which is why I've gotten into the habit of using tsup.

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

Successfully merging this pull request may close these issues.

2 participants