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

Conflicts with mini-css-extract-plugin #4

Open
crodriguez-plitzi opened this issue Dec 31, 2021 · 3 comments
Open

Conflicts with mini-css-extract-plugin #4

crodriguez-plitzi opened this issue Dec 31, 2021 · 3 comments

Comments

@crodriguez-plitzi
Copy link

hi, Testing this library i found problems with mini-css-extract-plugin, is there a way to solve this ?

ERROR in ./src/assets/index.scss
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
HookWebpackError: window is not defined
    at tryRunOrWebpackError (/home/carlos/htdocs/plitzi-sdk/node_modules/webpack/lib/HookWebpackError.js:88:9)
    at __webpack_require_module__ (/home/carlos/htdocs/plitzi-sdk/node_modules/webpack/lib/Compilation.js:4979:12)
    at /home/carlos/htdocs/plitzi-sdk/node_modules/webpack/lib/Compilation.js:5003:11
    at symbolIterator (/home/carlos/htdocs/plitzi-sdk/node_modules/neo-async/async.js:3485:9)
    at timesSync (/home/carlos/htdocs/plitzi-sdk/node_modules/neo-async/async.js:2297:7)
    at Object.eachLimit (/home/carlos/htdocs/plitzi-sdk/node_modules/neo-async/async.js:3463:5)
    at /home/carlos/htdocs/plitzi-sdk/node_modules/webpack/lib/Compilation.js:4879:16
    at symbolIterator (/home/carlos/htdocs/plitzi-sdk/node_modules/neo-async/async.js:3485:9)
    at done (/home/carlos/htdocs/plitzi-sdk/node_modules/neo-async/async.js:3527:9)
    at /home/carlos/htdocs/plitzi-sdk/node_modules/webpack/lib/Compilation.js:4794:8
-- inner error --
ReferenceError: window is not defined
    at webpack/runtime/live reloading runtime module:2:1
    at /home/carlos/htdocs/plitzi-sdk/node_modules/webpack/lib/javascript/JavascriptModulesPlugin.js:460:11
    at Hook.eval [as call] (eval at create (/home/carlos/htdocs/plitzi-sdk/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:9:1)
    at /home/carlos/htdocs/plitzi-sdk/node_modules/webpack/lib/Compilation.js:4981:39
    at tryRunOrWebpackError (/home/carlos/htdocs/plitzi-sdk/node_modules/webpack/lib/HookWebpackError.js:83:7)
    at __webpack_require_module__ (/home/carlos/htdocs/plitzi-sdk/node_modules/webpack/lib/Compilation.js:4979:12)
    at /home/carlos/htdocs/plitzi-sdk/node_modules/webpack/lib/Compilation.js:5003:11
    at symbolIterator (/home/carlos/htdocs/plitzi-sdk/node_modules/neo-async/async.js:3485:9)
    at timesSync (/home/carlos/htdocs/plitzi-sdk/node_modules/neo-async/async.js:2297:7)
    at Object.eachLimit (/home/carlos/htdocs/plitzi-sdk/node_modules/neo-async/async.js:3463:5)

Generated code for webpack/runtime/live reloading runtime module
 1 | 
 2 | if(!window.liveReload) {
 3 | window.liveReload = true
 4 | 	const socket = new WebSocket('ws://localhost:40001');
 5 | 	socket.addEventListener('open', function (event) {
 6 | 		console.log(`Client opened connection to server.`);
 7 | 	});
 8 | 
 9 | 	socket.addEventListener('message', function (event) {
10 | 		var message = JSON.parse(event.data);
11 | 		if (message.type === 'reload') {
12 | 			console.log('Reloading page due to reload event...');
13 | 			window.location.reload();
14 | 		}
15 | 	});
16 | 	socket.addEventListener('close', (event) => {
17 | 		console.log('Closing socket');
18 | 		socket.close();
19 | 	});
20 | 
21 | }
22 | 
 @ ./src/App.js 25:0-29
 @ ./WidgetEntryPointBootstrap.js 21:0-28 41:34-37 76:32-35
 @ container entry ./Sdk[0]

@danbiilee
Copy link

danbiilee commented Jun 20, 2022

Hi, I had the same issue too.

I couldn't find the reason, but I solved it by not using fmr in development mode.
So this way may not be appropriate if it must be separated into a css file even in development mode.

This is my webpack.config.js

const isDevelopment = process.env.NODE_ENV !== 'production'

module.exports = {
  ...
  module: {
    rules: [
	...
	{
	    test: /\.s?css$/,
	    use: [
	        isDevelopment
	            ? 'style-loader'
	            : MiniCssExtractPlugin.loader,
	        'css-loader',
	        'sass-loader',
	    ].filter(Boolean),
	},
    ]
  },
  plugins: [
    ...
    !isDevelopment &&
      new MiniCssExtractPlugin({
          filename: '[name].[contenthash:8].css',
      }),
  ].filter(Boolean),
}

@ScriptedAlchemy
Copy link
Member

send a pr
typeof window !== undefined should do it

@TristanBlg
Copy link

Hi, any news about this issue? I have the same pb

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

4 participants