Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@rollup/plugin-commonjs] commonjs does not recognize named cjs exports #1678

Open
GauBen opened this issue Feb 12, 2024 · 1 comment
Open

Comments

@GauBen
Copy link

GauBen commented Feb 12, 2024

I'm trying to transpile CJS to ESM until prisma/prisma#5030 is addressed. I'm having a hard time doing so as I can't quite get the pieces together.

Expected Behavior

The commonjs plugin properly detects all named exports

Actual Behavior

No named exports are found

Additional Information

There is a node-backed package that does a pretty solid named exports analysis, which works for my specific use case. I've added a npm run cjs-lex command in the repro to show how it works

@bhovhannes
Copy link
Contributor

I think my use case is related. I noticed that Object.defineProperty(exports, ...) syntax is also detected by cjs-module-lexer.

My input file input.js:

import {foo} from "foo"
console.log(foo)

The foo package is a pure CJS package and has the following content:

// foo/index.js
Object.defineProperty(exports, "foo", { enumerable: true, get: function () { return 123; } });

A bundle produced by Rollup outputs undefined when executed, while it should output value of foo - 123.

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

No branches or pull requests

2 participants