-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing selector when using sourcemaps, plugins, and compiling Less files in parallel #3574
Comments
@TopGrd That really isn't enough to go on, especially when it's an error in a package that Less doesn't maintain. Can you make a test repo with a minimal test case? Also, does this error occur when just using |
@endbay @TopGrd I'm not sure what's expected here. With no reproducible example, and with the error not thrown in Less itself, there's no hope in a resolution. Someone will need to set a breakpoint at that error and see what selector was expected and why it isn't present. |
One clue, this Less code is invalid: @root-name: business-bundle
/* other file */
.@{root-name} .wrapper{
/* css... */
}
|
I'm experiencing a similar problem in 3.13.0. (Still trying to find out a minimal reproduction.) Related code looks like: // button.less
@import "./lib.less";
.@{prefix}-button {
color: red;
&:hover {
color: blue;
}
} // lib.less
@import "./vars"; // where @prefix is defined Which is compiled as: {
color: red;
}
:hover {
color: blue;
} It's weird that no compilation error occurred. |
@matthew-dean It is a very huge project where error occurred. I am trying to reproduce it in a demo |
@root-name: business-bundle; Sorry, this is my code. It have a semi-colon. |
I use style-resources-loader to inject some global variables too. Maybe it has something to do with that? {
test: /\.less$/i,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: process.env.NODE_ENV === 'development',
reloadAll: true,
},
},
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
options: {
config: {
path: path.resolve(__dirname, '../postcss.config.js'),
},
},
},
{
loader: 'less-loader',
options: {
lessOptions: {
javascriptEnabled: true,
paths: [path.resolve(cwd, 'node_modules')],
},
},
},
{
loader: 'style-resources-loader',
options:{
patterns: path.resolve(
cwd,
'./node_modules/@somemodule/style/index.less',
),
injector: 'prepend',
},
},
],
}, |
Still cannot find out a simple reproduction. It's very weird that when hot module replacement is triggered and the compiled output of the changed file seems to be correct. And the problem only occurs for selector interpolation: @import "./lib.less";
.@{prefix}-button {
val: @prefix;
} Compiles to: {
val: foo;
} (Note the whole selector is missing, not only the interpolated part.) |
Can you expand on this a bit more? The compiled output from Less seems to be correct, but it's not getting replaced correctly? |
@Justineo This is a helpful clue. It's likely related to the resolution of this: #3434 In short, tree caching was removed from Less for a time, but it seemed to have too much of a negative performance impact in some scenarios, so I put it back in. It could be that Less is therefore not resetting some state of import trees, which ONLY causes an issue in a "live" environment where less.parse is called multiple times. Hmm, I wonder if I can test that theory in a reproduction. |
+1 Less @plugin + sourcemap will cause this problem |
@PengJiyuan Can you create a reproducible example in a cloneable repo? |
@matthew-dean Wait a minute, we create a mini repo. We have located this line of code, hope to help you solve it quickly... |
https://github.com/kirazxyun/less-question This repo can reproduce the problem. You can run with 'npm run build',then view the results in the dist folder. |
|
@matthew-dean We use @plugin and it affects all our projects, please help us 🙏 |
@PengJiyuan You're right, the code in question shouldn't fail outputting the chunk if source map building doesn't work. It should be like: if (inputSource === undefined) {
this._css.push(chunk);
return;
} That would be a short-term fix, with the longer term fix being figuring out why one of the files has an incorrect import mapping. (It's probably being re-used when compiled in parallel.) So I can do the temporary band-aid solution soon, and figure out the cause after. |
@PengJiyuan @kirazxyun @Justineo etc please try testing with |
Problem solved with less@3.13.0-alpha.3. Thank you Matt! |
@matthew-dean It works, thanks 🙏 |
@matthew-dean confirm that problem is solved with less@3.13.0-alpha.3, hoping for a official release soon |
It is solved with less@3.13.0-alpha.3. |
3.13.1 published |
4.0.0 is also published, which contains this fix. |
I have some code like bottom.
When webpack use less 3.12.2, that is ok. But when use 3.13.0, webpack build error.
The text was updated successfully, but these errors were encountered: