Skip to content

Fix native browser ESM loading - #122

Merged
zuchka merged 1 commit into
mainfrom
codex/fix-native-esm-browser
Aug 26, 2026
Merged

zuchka merged 1 commit into
mainfrom
codex/fix-native-esm-browser

Conversation

@zuchka

@zuchka zuchka commented Aug 26, 2026

Copy link
Copy Markdown
Owner

Summary

  • make index.mjs a self-contained native ES module that works in browsers and URL-based module loaders
  • preserve Node CommonJS/ESM function identity through a Node-specific ESM compatibility wrapper
  • expose the explicit remove-markdown/index.mjs subpath with matching ESM declarations
  • generate the portable ESM implementation from the canonical CommonJS source and fail tests if they drift
  • document direct browser ESM usage and the supported CDN/MIME-type boundary

Problem

The 0.7.0-rc.0 ESM entry imported its default export from index.js. Package-aware Node and Deno npm resolution treated that file as CommonJS and worked, but native browser and remote URL loaders parsed it as ESM and failed with:

The requested module './index.js' does not provide an export named 'default'

This follow-up to #119 removes that dependency from the portable ESM entry while retaining the established CommonJS behavior and Node interop.

Compatibility design

  • index.js remains the canonical, unchanged CommonJS implementation.
  • index.mjs is generated as a self-contained ESM implementation.
  • index.node.mjs remains a thin CommonJS interop wrapper for normal Node package imports.
  • Browser-aware resolvers select index.mjs; Node selects index.node.mjs.
  • The generation check runs during prepublishOnly and the module test suite.

Validation

  • 39 existing behavior tests
  • module and packed-tarball tests on Node 18, 20, 22, 24, and 26
  • real-browser unbundled index.mjs import
  • Deno 2.9.5 local, HTTP URL-module, and packed npm-package tests
  • TypeScript 4.7, 5.9, and 7 NodeNext consumers
  • Are the Types Wrong validation, including the explicit ESM-only entry
  • esbuild and Rollup browser-condition selection and runtime checks
  • pnpm 11.5, Yarn 4.18 Plug'n'Play, and Bun 1.4 consumers
  • 22,330 CommonJS/ESM differential assertions against published 0.6.4
  • successful npm publish dry run
  • zero production audit findings

Rollout

0.7.0-rc.0 is already published and immutable. After this merges, the next prerelease should be published as 0.7.0-rc.1 under the next dist-tag and receive a short browser-focused soak before promotion.

Performance issue #118 remains separate.

@zuchka

zuchka commented Aug 26, 2026

Copy link
Copy Markdown
Owner Author

@tukkek lmk your thoughts

@zuchka
zuchka merged commit 1b1485a into main Aug 26, 2026
11 checks passed
This was referenced Aug 26, 2026
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