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

Not working with an ESM build of React #1

Closed
high1 opened this issue Jun 4, 2020 · 4 comments
Closed

Not working with an ESM build of React #1

high1 opened this issue Jun 4, 2020 · 4 comments

Comments

@high1
Copy link

high1 commented Jun 4, 2020

Hello, I'm not really sure if this is the issue of the plugin, but the plugin does not work if I use pikapkg build of React, refresh functionality stops working. I'd really love to remove commonjs from the plugin chain, so if you have any idea what could the issue be, I'd really appreciate it.
OT, great job on the nollup and the article on Rollup and Webpack. I was able to run a typescript build with minor tweaks and have everything working almost OOTB with your example. I'll have to try it a bit more, but I'm suprised how little time I spent on configuring the bundler. Thanks.

@PepsRyuu
Copy link
Owner

PepsRyuu commented Jun 4, 2020

Good catch, haven't actually tried out the unofficial ESM versions. Will give it a look when I can. Do you have an example on how the React package is used?

@high1
Copy link
Author

high1 commented Jun 4, 2020

Actually, should be a drop-in replacement for the CJS builds. And it is, for the most part, but the plugin does not work.
npm install react@npm:@pika/react react-dom@npm:@pika/react-dom
I'm not sure what the issue is, but I've seen here that they've fixed the issue where the react-refresh was not working with CDN builds, which are ESM
react-refresh load from CDN? #17552, so I'm assuming that it should work.

@PepsRyuu
Copy link
Owner

PepsRyuu commented Jun 4, 2020

I pushed an example of it working here: https://github.com/PepsRyuu/rollup-plugin-react-refresh/tree/master/example-esm

The thing that gets it working is rollup-plugin-alias and pointing to the development versions of react and react-dom. Normally when you import the CJS version of React, it imports an index.js file. This file checks process.env.NODE_ENV to see if it should import the development or production version. This is why the replace plugin was needed. But since that's not browser compatible, that's omitted by the Pika version.

Let me know if this solves it for you! :)

@high1
Copy link
Author

high1 commented Jun 4, 2020

Development and build configurations tested, it's working fine. Jest breaks with ESM modules of React, but that's not relevant here. Closing, thanks.

@high1 high1 closed this as completed Jun 4, 2020
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