Noop in environment without DOM api
OlegWock opened this issue · 1 comments
Modification Proposal
Expected Behavior / Situation
When executed in environment without window
or document
(e.g. worker), style loader should not try to inject styles.
Actual Behavior / Situation
Fails with error while trying to access document.createElement
This was already discussed some time ago (#203), but I'm not sure if it was ever resolved. Please let me know if this is something you consider reasonable or if you think it's better to left it as is (raising exception)
I also made a ad-hoc fix for my project (forked this repo and tried to patch it diff), I'm not sure if it's sufficient and covers all cases (I use very basic configuration and patch works with it), but I'm willing to adjust it and make pull request if you find it useful
Please paste the results of npx webpack-cli info
here, and mention other relevant information
❯ npx webpack-cli info
System:
OS: macOS 13.1
CPU: (10) arm64 Apple M1 Max
Memory: 15.86 GB / 64.00 GB
Binaries:
Node: 16.18.1 - ~/.nvm/versions/node/v16.18.1/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v16.18.1/bin/yarn
npm: 8.19.2 - ~/.nvm/versions/node/v16.18.1/bin/npm
Browsers:
Brave Browser: 109.1.47.186
Chrome: 110.0.5481.177
Firefox: 110.0
Safari: 16.2
Packages:
babel-loader: ^8.2.5 => 8.2.5
clean-webpack-plugin: ^4.0.0 => 4.0.0
copy-webpack-plugin: ^11.0.0 => 11.0.0
css-loader: ^6.7.1 => 6.7.1
file-loader: ^6.2.0 => 6.2.0
filemanager-webpack-plugin: ^7.0.0 => 7.0.0
generate-file-webpack-plugin: ^1.0.1 => 1.0.1
moment-timezone-data-webpack-plugin: ^1.5.1 => 1.5.1
sass-loader: ^13.0.2 => 13.0.2
string-replace-loader: ^3.1.0 => 3.1.0
style-loader: git+https://github.com/OlegWock/style-loader => 3.3.1
terser-webpack-plugin: ^5.3.3 => 5.3.3
to-string-loader: ^1.2.0 => 1.2.0
ts-loader: ^9.4.2 => 9.4.2
webpack: ^5.75.0 => 5.75.0
webpack-bundle-analyzer: ^4.7.0 => 4.7.0
webpack-cli: ^5.0.1 => 5.0.1
Yeah, we should handle that case, do you want to send a PR? Sorry for delay