Skip to content

fix: emit type module marker in _types package.json - #467

Open
javadtavakoli wants to merge 1 commit into
wevm:0.xfrom
javadtavakoli:fix/types-package-json-module-marker
Open

javadtavakoli wants to merge 1 commit into
wevm:0.xfrom
javadtavakoli:fix/types-package-json-module-marker

Conversation

@javadtavakoli

@javadtavakoli javadtavakoli commented Sep 23, 2026 •

Copy link
Copy Markdown

Summary

  • Emit {"type":"module"} into src/_types/package.json during build:types, matching the existing _esm / _cjs markers
  • Fixes declaration files resolving as CommonJS under TypeScript module: node16 (TS1479 / TS1541)

This is the same fix that was accepted in viem: wevm/viem#4903. That change came out of wevm/viem#4843, which fixed viem's own _types/ marker and explicitly identified the bundled ox 0.14.x as the remaining source of the leftover TS1479s. This PR is that remaining half.

The problem

scripts/prepublish.ts does delete packageJson.type, so the published root package.json has no "type" field and defaults to CommonJS. build:esm and build:cjs each write a marker into the folder they emit, but build:types does not:

emitted folder package.json "type"
_esm/ "module" ✅
_cjs/ "commonjs" ✅
_types/ missing ❌

So every _types/**/*.d.ts is resolved as CommonJS. Those files use ESM syntax and import abitype, which is "type": "module" — a CJS file importing ESM:

node_modules/ox/_types/core/AbiFunction.d.ts(1,26): 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'.

This survives ox's own CI because check:types typechecks the source, never the emitted _types/ as a consumer resolves it through the exports map. It only appears downstream.

Reproduction

mkdir ox-repro && cd ox-repro
npm init -y && npm pkg set type=module
npm i ox@0.14.45 typescript@5.9.3

index.ts:

import * as AbiFunction from 'ox/AbiFunction'
export const f = AbiFunction.from('function approve(address, uint256)')
npx tsc --noEmit --strict --skipLibCheck false --module node16 --moduleResolution node16 index.ts
# 4x TS1479 + 3x TS1541, all inside node_modules/ox/_types/**

Verify the fix is exactly the missing marker:

printf '{"type":"module"}' > node_modules/ox/_types/package.json
npx tsc --noEmit --strict --skipLibCheck false --module node16 --moduleResolution node16 index.ts
# clean

Which configurations are affected

TypeScript module: node16 module: nodenext
5.7.3 ❌ fails ❌ fails
5.9.3 ❌ fails ✅ passes

TypeScript 5.8 taught nodenext that Node 22+ permits require(esm), so nodenext on current TypeScript no longer surfaces it — please reproduce with node16, which is still a fully supported setting and is what pins Node 16 CJS/ESM semantics.

I also hit this on a larger module: node16 project consuming ox through viem, where it produced 12 × TS1479 across 7 declaration files (Abi, AbiConstructor, AbiError, AbiEvent, AbiFunction, AbiItem, AbiParameters); adding the marker cleared all 12.

Why it's worth patching the 0.x line

viem@2.56.8 pins "ox": "0.14.45" exactly, so this reaches every viem consumer on node16 resolution, not just direct ox users. The workarounds today are turning on skipLibCheck or patching ox in node_modules — and library authors who re-export these types with declaration: true can't use skipLibCheck to hide it, since the mismatch propagates into their own emitted declarations.

ox@1.x is unaffected — it keeps "type": "module" on the published root and emits to dist/ — so this targets 0.x only.

Test plan

  • pnpm build:types writes src/_types/package.json containing {"type":"module"}
  • Marker present → the repro above typechecks clean with skipLibCheck: false; absent → TS1479/TS1541 as listed
  • Verified against both ox@0.14.45 and the current ox@0.14.47 tarball, neither of which ships _types/package.json

@vercel

vercel Bot commented Sep 23, 2026

Copy link
Copy Markdown

@javadtavakoli is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@javadtavakoli

Copy link
Copy Markdown
Author

Friendly ping @jxom — this is the ox half of wevm/viem#4903 (which you merged; wevm/viem#4843 identified the bundled ox@0.14.x as the remaining source of the TS1479s). It's a one-line build:types change targeting 0.x, and it affects every viem consumer on module: node16 since viem pins ox@0.14.x.

CI hasn't run yet — looks like the workflows need approval for a first-time contributor. Happy to adjust anything.

This branch has not been deployed

No deployments
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.

1 participant