webpack: Experiments.css reliance on fact that css should be loaded before js is a huge breaking change
Bug report/breaking change
Im trying experimental feature: #14893
Imagine you have following code index.js:
import './index.css'
addEventListener("DOMContentLoaded", (event) => {
//do something useful here
})
index.html:
<!DOCTYPE html>
<html>
<head>
<script src="./main.js"></script>
<link rel="stylesheet" href="./main.css"></link>
</head>
<body>
</body>
</html>
What is the current behavior? This code would fail:
Uncaught TypeError: __webpack_modules__[moduleId] is not a function
at __webpack_require__
If the current behavior is a bug, please provide the steps to reproduce. Here I made a repo to reproduce:
- Clone https://github.com/IdeaHunter/webpack-serve-css-modules-repro
yarn installyarn webpackoryarn webpack serve
What is the expected behavior? No error should happen or if its intended behavior there should be a friendly error message and there should be a breaking change entry in migration docs for webpack 6
Other relevant information: webpack version: 5.88.2 Node.js version: 18.16.0 Operating System: windows Additional tools: yarn
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 21 (17 by maintainers)
@alexander-akait maybe this shouldn’t be closed and should be tracked separately from https://github.com/webpack/webpack/issues/14893 , it’s actually a bug which cause experiments.css nearly impossible to work 100% right in production environment. if the css file is loaded after js start(which heavily depends on network status), the js will likely fail
We can do it, please write about it here https://github.com/webpack/webpack/issues/14893 with examples so we don’t forget about it, there are a lot of good improvements too
Close https://github.com/webpack/webpack/issues/14893, I added it and we need improve it