webpack errors after update to 3.0.0-beta.16
See original GitHub issueEnvironment
- Linaria version: 3.0.0-beta.16
- Bundler (+ version): webpack 5.65.0
- Node.js version: 17.2.0
- OS: Linux
Description
Hi there,
after upgrading to 3.0.0-beta.16, there are some errors in my webpack build that I cannot quite figure out on my own.
The first error is
Conflict: Multiple chunks emit assets to the same filename styles.css (chunks 179 and 532)
This seems to be related to my optimization.splitChunks.cacheGroups option that I have configured to include the CSS for lazy-loaded chunks into the main CSS chunk:
styles: {
name: 'styles',
idHint: 'styles',
test: /\.css$/,
chunks: 'all',
enforce: true,
}
If I comment that out, the actual webpack build seems to work fine again (and there is only one CSS chunk, so I’m not sure if that option is even still necessary) - but then I run into errors when starting webpack-dev-server (using React Fast Refresh):
ERROR in ./src/ui/main/main-container.tsx (./src/ui/main/main-container.linaria.css!=!../node_modules/@linaria/webpack5-loader/lib/outputCssLoader.js!./src/ui/main/main-container.tsx)
Module build failed (from ../node_modules/mini-css-extract-plugin/dist/loader.js):
HookWebpackError: Cannot read properties of undefined (reading 'exports')
at tryRunOrWebpackError (/home/michael/git/remote-mixer/node_modules/webpack/lib/HookWebpackError.js:88:9)
at __webpack_require_module__ (/home/michael/git/remote-mixer/node_modules/webpack/lib/Compilation.js:4979:12)
at __webpack_require__ (/home/michael/git/remote-mixer/node_modules/webpack/lib/Compilation.js:4936:18)
at /home/michael/git/remote-mixer/node_modules/webpack/lib/Compilation.js:5007:20
at symbolIterator (/home/michael/git/remote-mixer/node_modules/neo-async/async.js:3485:9)
at done (/home/michael/git/remote-mixer/node_modules/neo-async/async.js:3527:9)
at Hook.eval [as callAsync] (eval at create (/home/michael/git/remote-mixer/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
at /home/michael/git/remote-mixer/node_modules/webpack/lib/Compilation.js:4914:43
at symbolIterator (/home/michael/git/remote-mixer/node_modules/neo-async/async.js:3482:9)
at timesSync (/home/michael/git/remote-mixer/node_modules/neo-async/async.js:2297:7)
-- inner error --
TypeError: Cannot read properties of undefined (reading 'exports')
at Object.getModuleExports (/home/michael/git/remote-mixer/node_modules/@pmmmwh/react-refresh-webpack-plugin/lib/runtime/RefreshUtils.js:10:58)
at Module.<anonymous> (/home/michael/git/remote-mixer/node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].use[1]!/home/michael/git/remote-mixer/node_modules/@linaria/webpack5-loader/lib/outputCssLoader.js!/home/michael/git/remote-mixer/frontend/src/ui/main/main-container.tsx:23:62)
at /home/michael/git/remote-mixer/node_modules/webpack/lib/javascript/JavascriptModulesPlugin.js:432:11
at Hook.eval (eval at create (/home/michael/git/remote-mixer/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:1)
at /home/michael/git/remote-mixer/node_modules/webpack/lib/Compilation.js:4981:39
at tryRunOrWebpackError (/home/michael/git/remote-mixer/node_modules/webpack/lib/HookWebpackError.js:83:7)
at __webpack_require_module__ (/home/michael/git/remote-mixer/node_modules/webpack/lib/Compilation.js:4979:12)
at __webpack_require__ (/home/michael/git/remote-mixer/node_modules/webpack/lib/Compilation.js:4936:18)
at /home/michael/git/remote-mixer/node_modules/webpack/lib/Compilation.js:5007:20
at symbolIterator (/home/michael/git/remote-mixer/node_modules/neo-async/async.js:3485:9)
Reproducible Demo
I have created a branch in my remote-mixer project:
https://github.com/kryops/remote-mixer/tree/linaria3-beta16-error
(Edit: Now with 2 commits on top to fix the issues)
Going back one commit shows that 3.0.0-beta.15 does not seem to be affected.
You can use the following commands to reproduce the problems:
yarnto install the dependenciesyarn frontend buildruns a normal webpack build (you can verify that the result is ok by runningyarn buildand thenyarn start:prod)yarn startstarts the dev server
Thanks for looking into it!
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:11 (4 by maintainers)

Top Related StackOverflow Question
@kryops I’v reviewed your repo and got the following conclusion:
The `Cannot find module ‘undefined’ error should be fixed in https://github.com/callstack/linaria/pull/890 and is waiting to be released.
You should use
[name].cssfor the filename of mini-css-extract-plugin, although you may want to extra all CSS into one file, the output filename should be determined bycacheGroups.By changing that line, there should be two CSS file been generated to
frontend/distfolder. And if you force them tostyle.css, a conflict error thrown.distfolder ? You can use the type field of cacheGroups..linaria.cssbecame a virtual module, itsmodule.nameForCondition()which is used by SplitChunksPlugin also changed frompath/to/xxx.linaria.csstopath/to/xxx.tsx. Thetest: /\.css$/cannot match these CSS files anymore.In conclusion, this issue happened because of an outdate Webpack config and a bug in latest Linaria v2/v3 https://github.com/callstack/linaria/pull/890
cc @Anber
Regarding
[React Refresh] Failed to get exports for module: undefined.- this is fundamentally limited to react-refresh injecting itself into virtual modules like the following:My issue https://github.com/callstack/linaria/issues/897 is the same problem, manifested differently due to me overriding the entry module.
While making the injection check in react-refresh-webpack-plugin like so
match(moduleData.matchResource || moduleData.resource) &&it solves some of the cases, but the above module is still getting through and should be excluded at this step.It would be helpful if someone understood the nature of
.webpack[javascript/auto]type files. I couldn’t find anything on the internet so I’m a bit stumped for now.