jt
Back to the blog

skipLibCheck is not a fix

viem and ox, with over ten million weekly downloads each, shipped type declarations that broke under node16. The usual answer is skipLibCheck. I asked the maintainers to fix it instead, and the fix was one missing file.

  • typescript
  • open-source
  • libraries

If you've worked on a TypeScript project long enough, you've seen errors coming from inside node_modules. Errors in someone else's .d.ts files, in code you didn't write and can't change.

The common advice is one line in tsconfig.json:

"skipLibCheck": true

The errors go away and you move on. I did that for a long time too. This post is about the time I didn't, and why I think we should do it less.

skipLibCheck is not a fix. It hides the errors from you, your users still get them. With skipLibCheck false, 160 errors inside viem's types. With it true, 0 errors, but still there. With the missing _types/package.json added, 0 errors, actually fixed.

The errors

I was building a library on top of viem, the TypeScript library a large part of the Ethereum ecosystem uses to talk to the chain. My project used module: node16, strict, and skipLibCheck: false. One import:

import { createPublicClient, http } from 'viem'
export const client = createPublicClient({ transport: http() })

gave me 160 errors, all of them inside node_modules/viem/_types/:

node_modules/viem/_types/accounts/types.d.ts(1,41): error TS1541:
  Type-only import of an ECMAScript module from a CommonJS module
  must have a 'resolution-mode' attribute.

The root cause

viem publishes its code in three folders: _esm/ for ES modules, _cjs/ for CommonJS, and _types/ for the type declarations. The root package.json has no "type" field, so Node and TypeScript treat everything in it as CommonJS unless a folder says otherwise.

Two of the three folders say otherwise. Each has its own small package.json:

| folder | "type" | |---|---| | _esm/ | "module" | | _cjs/ | "commonjs" | | _types/ | missing |

So TypeScript reads every declaration file in _types/ as CommonJS. But those files are written in ESM syntax and import other ESM packages. A CommonJS file importing ESM is an error under node16, and TypeScript reports it for each import, 160 times.

The fix is one file:

echo '{"type":"module"}' > node_modules/viem/_types/package.json

That took me from 160 errors to 12. The last 12 came from ox, a lower-level library from the same team that viem depends on. ox had the exact same missing file.

Why nobody's CI caught it

Both projects type-check their source code, and the source is fine. Nobody type-checked the published package the way a user receives it: installed in node_modules, resolved through the exports map, with skipLibCheck off. The bug only exists there, so it only shows up for users.

And most users never see it, because:

  • Many projects use moduleResolution: bundler, which doesn't apply these rules.
  • TypeScript 5.8 taught nodenext that newer Node versions can require() ES modules, so nodenext on current TypeScript stops reporting it. To reproduce it, you need node16.
  • Almost everyone else has skipLibCheck: true.

This wasn't a new kind of problem, either. Back in 2023, in viem#244, a contributor suggested adding a test suite that builds small consumer projects with different tsconfig setups, to catch problems that "only occur when those types are consumed in a downstream library". That suite is exactly what would have caught this.

skipLibCheck hides it, it doesn't fix it

skipLibCheck: true tells TypeScript not to check any .d.ts file. On the same project, with the flag on, I got 0 errors. The 160 are still there, you just aren't told about them anymore.

That's fine when you're building an app and nobody depends on you. It stops being fine when you build a library.

If I publish a library on top of viem, my users' compiler loads viem's declarations through mine. I can turn on skipLibCheck for my own build, but I can't turn it on for them. Each of my users gets the same 160 errors, from a package they may not know they depend on, and the only advice I can give them is: turn on skipLibCheck too.

And that flag doesn't skip only viem. It skips every declaration file in their project, including real mistakes in mine. One missing file in a dependency, and everyone downstream has to turn off a safety check for all their libraries.

That's the chain I didn't want to be part of. The bug lives in one place. Every workaround copies it one step further downstream.

Workarounds travel downstream, fixes stay at the root. ox and viem both miss the _types marker, my library can't set flags for its users, and my users get 160 errors that aren't theirs. skipLibCheck makes every downstream project stop checking every .d.ts file. Fixing the root is one file in ox and viem, fixed once for everyone.

Asking was the better fix

So instead of turning the flag on, I opened an issue.

  • July 15, I opened viem#4843: the missing marker, a minimal repro, the one-line fix, and a note that the last 12 errors came from ox.
  • July 27, twelve days later, another contributor's PR, viem#4903, added the marker to viem's build. It was merged.
  • September 23, I opened ox#467 for the ox half, the same change on ox's 0.x line, which is the version viem pins.
  • November 8, after one friendly ping, the maintainer landed the change in ox#579, with me credited as co-author.

Today, with the latest viem, the same project, the same node16 config and skipLibCheck: false give zero errors.

The maintainers also didn't just copy my change in. They found a trade-off I hadn't covered: CommonJS projects on node16 that import ox now get an error in their own files, because one set of declarations serves both module systems. Their changeset tells those users to switch to nodenext or bundler. That's what fixing the root looks like when it's done properly: someone who knows the package weighs the cost and writes it down. A workaround in a user's tsconfig never gets that review.

What I'd ask of libraries, and of us

For library maintainers, especially big ones: type-check what you publish, not only what you write. Pack the package, install it in a small project with skipLibCheck: false, and compile it with a few moduleResolution settings, including node16. It's a short CI job, and it's the only place this kind of bug shows up.

For the rest of us: when the error is in node_modules, skipLibCheck is a fine way to keep working today. But spend the hour to find out why the error is there. If it's the package's fault, open an issue with a minimal repro and the fix if you have it. Mine was one issue and one small PR, and the fix now reaches everyone who installs viem.

The flag makes the error disappear for you. Reporting it makes it disappear for everyone.