You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: CJS detection regression for packages with "export" in comments
The content-based heuristic (`code.includes("export ")`) was fooled by
CJS files containing the word "export" in comments — e.g.
`@opentelemetry/api`'s CJS entry has a comment:
// TODO: Remove ProxyTracerProvider export in the next major version.
This caused the CJS shim to be skipped, leaving `exports` undefined
when Vite's ESModulesEvaluator ran the file.
Replace the naive string check with two-layer detection:
1. Package.json "type" field (Node.js semantics): .cjs is always CJS,
.js is CJS unless the nearest package.json has "type": "module".
Results are cached per directory.
2. ESM statement regex fallback: for dual CJS/ESM packages that ship
ESM in .js without "type": "module" (e.g. @opentelemetry/api),
detect actual ESM syntax (export/import statements) including
minified forms like `import{` and `export*from`.
Also adds a test that imports from a real CJS npm package (qs) in
node_modules, since the existing CJS test fixtures were local ESM
files that never exercised the shim path.
0 commit comments