-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
Labels
bugSomething isn't workingSomething isn't workingdogfoodFound during dogfoodingFound during dogfooding
Description
Found during dogfooding v3.1.4
Severity: Medium
Command: Programmatic API via require()
Reproduction
npm init -y && npm install @optave/codegraph@3.1.4
node -e "const cg = require('@optave/codegraph'); console.log(Object.keys(cg))"Expected behavior
CJS require() should work, returning the module exports.
Actual behavior
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in .../node_modules/@optave/codegraph/package.json
Root cause
The exports field in package.json only defines an import condition:
"exports": {
".": {
"import": "./src/index.js"
}
}There is no require or default condition. Since the package is "type": "module", CJS consumers need an explicit export path.
Suggested fix
Either:
- Add a CJS wrapper:
"require": "./src/index.cjs"(needs a wrapper file), or - Add
"default": "./src/index.js"to the exports (Node.js will attempt to load ESM, which works in some contexts), or - Document that the package is ESM-only and CJS consumers must use dynamic
import().
Option 3 is the simplest if CJS support isn't a priority.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingdogfoodFound during dogfoodingFound during dogfooding