-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
[SOLVED] Webpack: Error in window is not defined during deploy with "window" used in necessary node modules #7112
Comments
webpack runs in a Node environment, if some of your dependencies rely on const isClient = typeof window !== 'undefined' or when loading dependencies let particles
if (typeof window !== 'undefined') {
particles = require('particles.js')
} |
I encourage you to ask your question on StackOverflow instead. We try to use the issue tracker for bug reports and feature requests, as well as some discussions, but this appears to be a very localized question. I’m closing for these reasons. |
@montogeek I want to try with your suggested solution, but since I'm a newbie to webpack i really need to ask you: where should I put these code snippets exactly? In webpack.config.js, in my angular app entry point,...? Thanks in advance! ( I've asked it on stackoverflow before but I didn't have a real working solution, looks like no one has a real workaround for this and looking on other related issues on github I've never found some pratical examples as solutions... So I'm asking here because I also want to give help to other users providing them a pratical example, obviously I hope It's not a problem or to not go against some rules with this ) |
You should put them whatever you need to use Read more about globals in different environment here: https://www.hacksparrow.com/global-variables-in-node-js.html There is ton of articles about how globals differ on Browser and Node.JS environment but in a nutshell:
|
🎉 🍻 SOLVED ✔️ 🍻 🎉 Changed this: In this: So I've actually: I don't know why it was causing errors in libraries but I've seen that with other loaders it works pretty fine. |
Congrats! |
Actually I need a part of the library, but the library is bloated and imports another file that depends on window. I can't use your solution. For example I need PIXI.Point, which works fine on node.js, but importing pixi.js it will import the whole file which has a window reference. |
@pundoo's webpack config update suggestion to use ProvidePlugin just changed the error to:
|
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
"Error in window is not defined" in main.js file during deploy.
I am not using "window" in my code and node_modules using it are all necessary so i have to use them.
If the current behavior is a bug, please provide the steps to reproduce.
There aren't much steps to describe. I simply get this error, but this doesn't provide me more infos...
Error blinks up during execution of "node node_modules/webpack/bin/webpack.js --mode=production --env.prod" command.
What is the expected behavior?
It should execute the command without any problem.
What can I do if window is used inside some necessary node_modules?
If this is a feature request, what is motivation or use case for changing the behavior?
Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.
Related to every other issue about this problem, which solutions haven't been helpful, unluckily...
Webpack version: 4.6.0
Node version: 5.6.0
Operating system: windows 10.
ERROR:
webpack.config content:
The text was updated successfully, but these errors were encountered: