-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
window is undefined #385
Comments
You should fork the repo, remove the browser field from your fork, and add it as a github dep:
If the package requires compilation, try adding the build directories to version control Another workaround is creating a temporary npm package. Let me know how this works out. |
There's probably a webpack option like |
I have this problem too. The underlying problem is that Webpack doesn't fully understand the electron nor electron-main when trying to figure out if the target is web or not. One fix is to add this to webpack.config.electron.js:
Another fix appears to be to bump the webpack version. Pull request coming. |
I'm testing this fix out. I cleaned my node_modules folder and the fix doesn't seem to work anymore. Not sure if it's dependent on a specific version of webpack. But I think the root cause is still this. webpack (1.x) defaults to browser when packageAlias is not set. |
@worldjoe indeed , doesn't work for me either :( |
@worldjoe so far the fork and removing the browser from package.json only works, hopefully there is going to be a better one |
I believe this is a webpack issue or an issue with the package itself. I had to do this for my own projects that use this boilerplate. |
The problem is in webpack. https://github.com/webpack/webpack/blob/webpack-1/lib/WebpackOptionsDefaulter.js#L75 this code should doesn't understand the electron nor electron-main target. It should probably look like this: function defaultByTarget(value, web, webworker, node, nodeWebkit, def) {
if(value !== undefined) return value;
switch(options.target) {
case "web":
return web;
case "webworker":
return webworker;
case "node":
case "electron":
case "electron-main":
case "async-node":
return node;
case "node-webkit":
return nodeWebkit;
default:
return def;
}
} I need to do more testing. |
OK. sorry for all the speculation. For starters, the base configuration shouldn't have a packageMain of browser listed: Also, webpack-merge won't let you override so simply restating the packageMain in webpack.config.electron.js doesn't work. |
Can someone else verify? Add these lines to webpack.config.development.js
webpack.config.electron.js:
webpack.config.base.js:
|
@worldjoe yes, it fixes the issue! |
I have an electron app build on top of "electron-react-boilerplate". When I try to use build and then run I'm getting an error "window is undefined".
After some investigation it turn out that the problem is related with package "form-data"
"The easy fix" is to simply remove browser param from package.json for "form-data" in node-modules.
Now the main question is that somehow related to form-data itself or a webpack or the configuration for webpack in this project.
I have already post the same question in "form-data" repo
form-data/form-data#252
Any idea how this could be solved in a proper way would be really useful,
thx :)
The text was updated successfully, but these errors were encountered: