catamphetamine / webpack-isomorphic-tools

Server-side rendering for your Webpack-built applications (e.g. React)
MIT License
1.25k stars 48 forks source link

getting window error when trying to import scss from node_module #140

Closed idangozlan closed 7 years ago

idangozlan commented 7 years ago

Hi, when im trying to import css from node module, im getting the following error:

[webpack-isomorphic-tools/plugin] [error] ReferenceError: window is not defined
    at /myproject/node_modules/style-loader/lib/addStyles.js.webpack-module:24:9
    at /myproject/node_modules/style-loader/lib/addStyles.js.webpack-module:13:46
    at module.exports (/myproject/node_modules/style-loader/lib/addStyles.js.webpack-module:58:46)
    at Object.<anonymous> (/myproject/~/react-select/dist/react-select.css.webpack-module:13:61)
    at Module._compile (module.js:570:32)
    at Object._module2.default._extensions.(anonymous function) [as .webpack-module] (/myproject/node_modules/require-hacker/babel-transpiled-modules/require hacker.js:280:12)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at safe_require (/myproject/node_modules/webpack-isomorphic-tools/babel-transpiled-modules/plugin/write assets.js:641:10)
    at populate_assets (/myproject/node_modules/webpack-isomorphic-tools/babel-transpiled-modules/plugin/write assets.js:607:32)
    at write_assets (/myproject/node_modules/webpack-isomorphic-tools/babel-transpiled-modules/plugin/write assets.js:87:2)
    at Compiler.<anonymous> (/myproject/node_modules/webpack-isomorphic-tools/babel-transpiled-modules/plugin/plugin.js:213:45)
    at Compiler.applyPlugins (/myproject/node_modules/tapable/lib/Tapable.js:61:14)
    at /myproject/node_modules/webpack/lib/Compiler.js:271:13
    at Compiler.emitRecords (/myproject/node_modules/webpack/lib/Compiler.js:367:37)
    at /myproject/node_modules/webpack/lib/Compiler.js:265:12
    at /myproject/node_modules/webpack/lib/Compiler.js:360:11
    at next (/myproject/node_modules/tapable/lib/Tapable.js:154:11)
    at Compiler.compiler.plugin (/myproject/node_modules/webpack/lib/performance/SizeLimitsPlugin.js:99:4)
    at Compiler.applyPluginsAsyncSeries1 (/myproject/node_modules/tapable/lib/Tapable.js:158:13)
    at Compiler.afterEmit (/myproject/node_modules/webpack/lib/Compiler.js:357:8)
    at Compiler.<anonymous> (/myproject/node_modules/webpack/lib/Compiler.js:352:14)
    at /myproject/node_modules/webpack/node_modules/async/dist/async.js:421:16
    at iteratorCallback (/myproject/node_modules/webpack/node_modules/async/dist/async.js:998:13)
    at /myproject/node_modules/webpack/node_modules/async/dist/async.js:906:16
    at /myproject/node_modules/graceful-fs/graceful-fs.js:43:10
    at FSReqWrap.oncomplete (fs.js:123:15)

any suggestions?

catamphetamine commented 7 years ago

Well, apparently, style-loader/lib/addStyles.js uses window variable which breaks Node.js. You could check that out by looking at the file.

idangozlan commented 7 years ago

Thanks! Do you have any clue if it's something new or you bumped into that on past?

catamphetamine commented 7 years ago

No one reported that before you so maybe it's a new style-loader release or maybe something else

xinghengwang commented 6 years ago

I have the same issue. Can you double check? Style-loader only supposes to work on the client side, since it is trying to insert a style tag into the DOM. We setup correctly with webpack for style-loader as a fallback, still, whenever we run build, it gets an error.

catamphetamine commented 6 years ago

Well, the cause of the issue is the same: style-loader seems to use window variable in your case which is normal considering it adds styles to the <head/>. Only two people had this issue so far. You could create a simple example project illustrating the issue along with the instructions for reproducing it and then I could have a look.