-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
Webpack dev server loads @material-ui and react differently #420
Comments
This is not related to an import starting with @. You can read a lot about it if you search he issues here. There is also documentation at https://webpack.electron.build/configuration#white-listing-externals My recommendation:
|
Furthermore, the problem at its core is that you need to have exactly one copy of react in your project. Otherwise you run into exactly your problem. |
Yes this fixes this issue, as well as
or the other way around "electronWebpack": {
"whiteListedModules": ["@material-ui/core"],
} in Is there a reason for react to be whitelisted by default? |
Hehe. Well... It's complicated, and needlessly so :) "Whitelisting" in electron-webpack basically means "do not automatically put this package to the webpack externals". So at some point, one collaborator added react as default, because that too seemed to make sense (else you always had to whitelist it). My stance on this is: bollocks! Let's make a major update with a breaking change and remove the externals/whitelisting feature altogether. The only stuff I actually ever needed to be treated as external was stuff I needed in the main process. Never ever had it been anything from the renderer process. And that makes sense - why shouldn't the renderer just run any bundle as if it was an actual web page. No externals needed, put it all in the bundle. On main process, using stuff like sqlite or some native modules etc, there it makes sense to not try squeeze it into a bundle the same way as with a website. But users who need that will find it out and manually add lib xy to webpack externals. I mean, if you'd run into this problem, you'd be doing sophisticated stuff already and would probably understand a bit about coding, webpack, electron etc. |
I have the same problem, this works for me, thank you very much! |
Steps to reproduce
git clone https://github.com/electron-userland/electron-webpack-quick-start.git
cd electron-webpack-quick-start
yarn add react react-dom @material-ui/core
src/index/renderer.js
yarn dev
Expected results:
I see a window with a nice gradient.
Actual results:
I see a white window with following error in developers console:
As you may see in a stack trace React is first loaded via webpack dev server (webpack-internal://),
but @material-ui and its dependencies are loaded via direct file access (file://).
This leads to 2 copies of React being used in the same app (case 3 in error message).
I suspect it is caused by alias from
@
to sourceDir.Workaround
So far I have managed to circumvent this issue by using webpack alias without
@
in the name.package.json
renderer.webpack.js
src/rendered/index.js
The text was updated successfully, but these errors were encountered: