-
-
Notifications
You must be signed in to change notification settings - Fork 594
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
[commonjs] bundle React after deprecated namedExports
#423
Comments
The culprit seems to be an if-statement at the head of if (process.env.NODE_ENV !== "production") { Inside of that isn an IIEF that modifies Uncommenting the if-statement produces a working bundle: |
And adding |
The unused variables are indeed rather useless but it looks to me that otherwise, |
This is certainly a problem with the React package itself, but earlier versions of the commonjs plugin had an escape hatch with |
@lukastaegert this is about being able to import named exports in addition to default. In fact, the cjs source for React only exports named exports:
|
...actually, that's not correct either. The entry file re-exports all named exports as default: module.exports = require('./cjs/react.development.js'); So Rollup is correct here, but users of React expect and rely upon named exports, and without the |
Well, the problem is that for CommonJS, the concept of a named export is only an illusion: There only is an |
The use case here is "next generation" dev environments like Snowpack or (my) dvlp that run cjs packages through Rollup to convert them to esm for import directly in the browser (without further bundling). So |
Well, since it is an entry point you could also just bundle an ESM wrapper file that imports React and exports the relevant properties as actual named exports. I do not see how this is much more effort than manually maintaining a list of named exports in a config file and it would make things more explicit. Or of course bother the React time to switch to this hipster module format that was developed only five years ago. But another story for another time I guess... |
Ok, will try my luck with a custom wrapper. |
I think something as simple as export {Component, Fragment, useState, …} from 'react' should work wonders and should provide minimal overhead. |
@lukastaegert, could you explain me please how stupid me can fix the problem error-name-is-not-exported-by-module without |
If React is bundled dependency and you use latest The issue here is that people want to bundle React as an entry point that should have the correct exports. As automatic named export detection is not possible due to the way React is distributed, you would make the wrapper your entry point instead. But to me it sounds this is not what you want to do. |
@lukastaegert you right, I have error-name-is-not-exported-by-module error with xferno package, using link from error I found in docs that namedExports can fix that, but I see that already deprecated |
@lukastaegert Been working on adding support for peer dependencies in my rollup wrapper. I do not see a way to force peer deps to use default export rather than named exports for react or any other similar package, any idea what should I be doing? |
It is a small wrapper around tg-named-routes which allows one to have language specific routes. Also: - Updated rollup and plugins to resolve issue with React named imports - see rollup/plugins#423 (comment) - Updated react used in development - Updated react-router/react-router-dom
It is a small wrapper around tg-named-routes which allows one to have language specific routes. Also: - Updated rollup and plugins to resolve issue with React named imports - see rollup/plugins#423 (comment) - Updated react used in development - Updated react-router/react-router-dom
It is a small wrapper around tg-named-routes which allows one to have language specific routes. Also: - Updated rollup and plugins to resolve issue with React named imports - see rollup/plugins#423 (comment) - Updated react used in development - Updated react-router/react-router-dom
It is a small wrapper around tg-named-routes which allows one to have language specific routes. Also: - Updated rollup and plugins to resolve issue with React named imports - see rollup/plugins#423 (comment) - Updated react used in development - Updated react-router/react-router-dom
It is a small wrapper around tg-named-routes which allows one to have language specific routes. Also: - Updated rollup and plugins to resolve issue with React named imports - see rollup/plugins#423 (comment) - Updated react used in development - Updated react-router/react-router-dom
I am curious if anyone has found a solution to getting react named exports to work with rollup? This issue was closed, but there still doesnt seem to be any solution |
It's July 2023 and there still seems to be no solution. We deprecated the option that actually fixed this? I don't understand, there's no way no one uses Rollup with React and, let's say, React Router in production. How is this issue not bustling with activity. And since it's not, is someone sitting on a solution and not sharing it? Lol |
NEVERMIND, I slept on this and it's about just providing the /node_modules/ regex in the
That first one is my monorepo dependency. |
How Do We Reproduce?
https://repl.it/repls/RoundedSnoopyBackend
input: require.resolve('react')
, and with@rollup/[email protected]
and@rollup/[email protected]
pluginsesm
output fileExpected Behavior
All React named exports are exported.
Actual Behavior
Named exports are assigned to local variables but not exported:
The text was updated successfully, but these errors were encountered: