-
-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
CLIbugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or requestfeaturehelp wantedExtra attention is neededExtra attention is needed
Description
Problem Description:
Currently, the package is configured as "type": "module" in package.json, which makes it ESM-only. This causes issues when other developers or tools try to require('flossum') in a CommonJS environment, resulting in the error:
❌ The package doesn't seem to have a CommonJS entry point
Goal: Update flossum to support both CommonJS (require) and ESM (import) so it can be used in any environment.
Proposed Directory Structure:
flossum/
├── src/
│ └── index.js # Source code (ESM)
├── dist/
│ ├── index.mjs # Output ESM build
│ └── index.cjs # Output CJS build
├── package.json
package.json Changes:
{
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"exports": {
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
},
"bin": {
"flossum": "./dist/index.mjs"
},
"scripts": {
"build": "node build.mjs"
}
}
Build Setup:
Use esbuild to generate both ESM and CJS builds:
npx esbuild src/index.js --bundle --platform=node --format=esm --outfile=dist/index.mjs
npx esbuild src/index.js --bundle --platform=node --format=cjs --outfile=dist/index.cjs
Optional: Automate with a build.mjs script or directly in package.json.
Resulting Usage:
✅ import { fn } from 'flossum' — works in ESM
✅ const { fn } = require('flossum') — works in CommonJS
✅ CLI remains intact
Test Checklist:
npm packworks without warningrequire('flossum')in CJS project worksimportin ESM project works- CLI (flossum) functions the same
npm publish --dry-runis clean
Note:
- No need to change
"type": "module"— just generate a.cjsfile as fallback. - Avoid
index.jsambiguity — always use.mjsand.cjsfor clarity in dual support. - This setup ensures compatibility with Node.js, bundlers, and all modern tooling.
Metadata
Metadata
Assignees
Labels
CLIbugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or requestfeaturehelp wantedExtra attention is neededExtra attention is needed