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 pack works without warning
require('flossum') in CJS project works
import in ESM project works
- CLI (flossum) functions the same
npm publish --dry-run is clean
Note:
- No need to change
"type": "module" — just generate a .cjs file as fallback.
- Avoid
index.js ambiguity — always use .mjs and .cjs for clarity in dual support.
- This setup ensures compatibility with Node.js, bundlers, and all modern tooling.
Problem Description:
Currently, the package is configured as
"type": "module"inpackage.json, which makes it ESM-only. This causes issues when other developers or tools try torequire('flossum')in a CommonJS environment, resulting in the error:Goal: Update
flossumto support both CommonJS (require) and ESM (import) so it can be used in any environment.Proposed Directory Structure:
package.jsonChanges:Build Setup:
Use
esbuildto generate both ESM and CJS builds:Optional: Automate with a
build.mjsscript or directly inpackage.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 worksnpm publish --dry-runis cleanNote:
"type": "module"— just generate a.cjsfile as fallback.index.jsambiguity — always use.mjsand.cjsfor clarity in dual support.