Skip to content

fix: correct dual-package hazard in package exports#237

Merged
Joeri van Oostveen (jvanoostveen) merged 4 commits into
mainfrom
fix-exports
Jul 7, 2026
Merged

fix: correct dual-package hazard in package exports#237
Joeri van Oostveen (jvanoostveen) merged 4 commits into
mainfrom
fix-exports

Conversation

@jvanoostveen

Copy link
Copy Markdown
Member

package.json declared "type": "module" but "main" still pointed to the
CommonJS build (dist/maquette.cjs.js). Because the file extension was
.js, Node/Vite parsed it as ESM despite its CommonJS content, causing
"ReferenceError: exports is not defined" in consumers.

Rename the CJS build output to dist/maquette.cjs (unambiguous
CommonJS regardless of "type": "module") and add an explicit exports
map so import/require resolve to the correct build.

package.json declared "type": "module" but "main" still pointed to the
CommonJS build (dist/maquette.cjs.js). Because the file extension was
.js, Node/Vite parsed it as ESM despite its CommonJS content, causing
"ReferenceError: exports is not defined" in consumers.

Rename the CJS build output to dist/maquette.cjs (unambiguous
CommonJS regardless of "type": "module") and add an explicit exports
map so import/require resolve to the correct build.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a dual-package resolution hazard where the package is marked "type": "module" but previously pointed "main" at a CommonJS build with a .js extension, causing some consumers to parse the CJS file as ESM and fail at runtime.

Changes:

  • Rename the CommonJS entrypoint from dist/maquette.cjs.js to dist/maquette.cjs via the "main" field.
  • Add an explicit "exports" map so import and require resolve to the correct builds (and expose ./package.json).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread package.json
@jvanoostveen Joeri van Oostveen (jvanoostveen) merged commit bc65e20 into main Jul 7, 2026
6 checks passed
@jvanoostveen Joeri van Oostveen (jvanoostveen) deleted the fix-exports branch July 7, 2026 08:19
@darksabrefr

Copy link
Copy Markdown

To create a fully functional ESM library in Node, you also need to explicitly add the .js extensions in imports in all source files. Extensionless imports are supported by bundlers but not by Node in ESM mode.

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.

4 participants