Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build modern CommonJS and support package.json exports #336

Merged
merged 12 commits into from
Jan 21, 2025

Conversation

enisdenjo
Copy link
Collaborator

@enisdenjo enisdenjo commented Jan 16, 2025

Use node16 for building CJS

Warning

Unless moduleResolution is explicitly set to classic, node or node10 - then commonjs (Node <v12 style CJS) will be used.

Output leaves dynamic import() calls as-is, so CommonJS can asynchronously import ESM (Node can import ESM from CJS).

node16 and nodenext are the only correct module options for all apps and libraries that are intended to run in Node.js v12 or later, whether they use ES modules or not.

TypeScript documentation

Node.js v12 security support reached EOL in 2022 (and active support in 2020).

Use node16 or nodenext or es2022 for building ESM

If the nearest tsconfig.json's moduleResolution is either node16 or nodenext, the module will use that value. Otherwise, it'll use es2022.


Aside from building to "modern" CJS, another benefit of using module: node16 is that it works with moduleResolution: node16 | nodenext (allowing the usage of exports field in package.json) whereas module: commonjs doesn't.

Copy link

changeset-bot bot commented Jan 16, 2025

🦋 Changeset detected

Latest commit: 1c6814b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
bob-the-bundler Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Jan 16, 2025

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
bob-the-bundler 8.0.0-alpha-20250116201822-1c6814b11c3fec160bbf4b301ed13402ff664183 npm ↗︎ unpkg ↗︎

@enisdenjo enisdenjo merged commit 407c0be into master Jan 21, 2025
6 checks passed
@enisdenjo enisdenjo deleted the modern-dual-cjs branch January 21, 2025 16:28
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