linaria: webpack build silently fails after Linaria update
Hi there,
I have a mysterious problem in one of my projects after updating to the current version of Linaria: The webpack build seems to crash, but it does not report any error - it just exits without writing anythin on disk.
I managed to track down the change in Linaria that causes the problem, I just can’t figure out what’s happening exactly. Thanks for having a look! 😅
Environment
- Linaria version: 4.2.2
- Bundler (+ version): webpack 5.75.0
- Node.js version: 19.1.0
- OS: ArchLinux
Description
I do not really understand what is happening - maybe an error that leads to a crash, but the error is then swallowed somehow?
I managed to track it down to https://github.com/callstack/linaria/pull/1086 (CC @Anber ): It starts working again when I pin @linaria/babel-preset to 4.2.2, or comment out the await mutex that was introduced there.
Reproducible Demo
I was unable to provide a minimal reproduction, as only one of my projects is affected, and I don’t know which code there causes it.
I created a branch with a reproduction here: https://github.com/kryops/vlight/tree/linaria-babel-preset-error
Just execute yarn, which should build everything.
The output is:
...
[BABEL] Note: The code generator has deoptimised the styling of /home/michael/git/vlight/node_modules/@mdi/js/mdi.js as it exceeds the max of 500KB.
[BABEL] Note: The code generator has deoptimised the styling of /home/michael/git/vlight/node_modules/@mdi/js/mdi.js as it exceeds the max of 500KB.
➤ YN0000: Done with warnings in 42s 859ms
(the [BABEL] message is repeated 4 times)
Nothing is written into the frontend/dist folder.
The successful build output on the main branch looks like this:
...
[BABEL] Note: The code generator has deoptimised the styling of /home/michael/git/vlight/node_modules/@mdi/js/mdi.js as it exceeds the max of 500KB.
[BABEL] Note: The code generator has deoptimised the styling of /home/michael/git/vlight/node_modules/@mdi/js/mdi.js as it exceeds the max of 500KB.
6 assets
774 modules
webpack 5.75.0 compiled successfully in 33886 ms
➤ YN0000: Done with warnings in 54s 906ms
(the [BABEL] message is repeated more than 4 times)
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 17 (1 by maintainers)
@garthenweb I’ve checked how Linaria works with esbuild. Half of the test cases don’t work. It means that if imported code is transpiled with esbuild, Linaria cannot resolve its dependency graph and detect unnecessary code. I’ll fix it asap.
+1
I have encountered this issue too. I am using npm package
inversifywhich has a circular require inside it. After some investgations into internal codes of linaria, I make it work by copying the default rules ofEvalRulehttps://github.com/callstack/linaria/blob/master/docs/CONFIGURATION.md#:~:text=The default setup is%3A
Actually the default rules in the document is not the default rules in the code. That’s confusing.
The
await mutextakes me a lot of debugging time to find it because everything become idle. Is there any way to make a “timeout” to inform possible circular deps?Trying to update from Linaria 2.3.1 I also experience this issue where webpack stops without error. When provided with the option
progress, webpack gets stuck:10% building 0/x entries 1/y dependencies 0/z modulesLooking at this issue, I suspect we have circular dependencies in our app too. So I ran
dpdm --no-warning --no-tree ./src/*.tsand found only type dependencies in the report (the output with-Toption is green ✅ ).Since then, I’ve been looking for a reproduction case.
Setup
Mini repro case
The smallest code to confuse Linaria’s build is the following:
App.tsB.tsPS: I’m also looking at more intricate examples because I feel this doesn’t give the full picture. I’ve been able to build similar code in some cases, but at some point it fails when the dependency tree grows. I have a hunch
enumare part of the problem (because are type and value at the same time) maybe?@garthenweb maybe it does. If you have a lot of packages that are transpiled with esbuild, Linaria may struggle with resolving the whole dependency tree. I’m going to add esbuild to the list of tested compilers and check if it works or not. I’ll let you know in a day.
Thanks for the hints, that makes sense. When exploring the behaviour I found similarities to what you describe. If we can remove the unneeded parsing, the issue would reduce quite a lot. It might be sufficient for 95% of the cases. In combination with a proper warning in case it still happens it is most probably easy enough to work around.
I will try to come up with an example repo as soon as I find time for it 😃
Hi @kryops!
Probably, you have a circular dependency somewhere. However, it is not a legit reason to crash without any error messages 😃