Skip to content

Publish as ESM #4429

@dynst

Description

@dynst

This would solve...

undici/package.json

Lines 62 to 63 in 74d505f

"main": "index.js",
"types": "index.d.ts",

Bundlers are much better at tree-shaking ESM than they are at CJS.

The implementation should look like...

"build:node": "esbuild index-fetch.js --bundle --platform=node --outfile=undici-fetch.js --define:esbuildDetection=1 --keep-names && node scripts/strip-comments.js",

Build with a transpiler like tsdown instead of esbuild.

I have also considered...

Additional context

https://antfu.me/posts/move-on-to-esm-only
https://joyeecheung.github.io/blog/2024/03/18/require-esm-in-node-js/

Node.js v18 support was already dropped last year, so there's no compatibility benefit in (dual-)publishing CommonJS code at this point. #3880

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions