ng-bootstrap: Rules skipped due to selector errors: legend+* -> Cannot read property 'type' of undefined
Bug description:
When building angular using the production configuration, the step Generating index html... produces following warning:
1 rules skipped due to selector errors: legend+* -> Cannot read property 'type' of undefined
See this screenshot:

Reproduction Steps
In Terminal:
ng new testproject --style scss
cd testproject
ng add @ng-bootstrap/ng-bootstrap
npm run build
Versions of Angular, ng-bootstrap and Bootstrap:
Angular: 13.3.0 - 13.3.2
ng-bootstrap: 12.0.2
Bootstrap: 5.1.3
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 27
- Comments: 76 (2 by maintainers)
Had the same issue. Managed to solve it by replacing
"optimization": trueinangular.jsonwithAs suggested in https://mdbootstrap.com/support/angular/angular-12-production-build-warning-mdb4-12/
These additional properties (added to the “production” section in the “angular.json” file) solved my problem, and the warning message disappeared.
I get even two messages:
Disabling
inlineCriticalin angular.json as others suggested helped me get rid of this warning fromng buildoutput. However, the warning was still present innpm run dev:ssroutput, as I am using Angular Universal. I was able to get rid of this one as well, by settinginlineCriticalCsstofalseinngExpressEngineoptions (server.ts file).Edit: Regarding
inlineCriticalthere is also:The option was introduced with Angular 12. Normally, I am against disabling features to get rid of a warning, but in this case it seems like a reasonable solution.
It’s because you installed bootstrap and ng-bootstrap
it’s working, you need to add it to production in angular.json
I had the same issue, which solved by adding below code to the production section in angular.json file.
“optimization”: { “scripts”: true, “styles”: { “minify”: true, “inlineCritical”: false }
Brand new Angular 17.1.2 project getting this error on a production build.
I’m having the same issue after upgrading to angular 17 and using the new commonengine with SSR
Is there a solution ?
@kmlbdh you are right. Thanks for the clarification. The
production configurationof myangular.jsonlooks like this@enirtak, no this is not a solution, it is a poor workaround where you disable optimization.
The proper solution is to upgrade to Angular 16.1.0, which includes the proper fix.
This is the solution in October 2023 with Angular 16 and Bootstrap 5.
I continue having the same warning 😦
The same warning was received upon creating a new empty angular 13.3.3 app with bootstrap 5.3.1.
I don’t think disabling optimisation is a great idea, instead you can override the version of
css-select(a dependency of critters, which is causing the issue) with npm, add the below snippet topackage.jsonand donpm installand you should find it’ll override the dependency for now.(If you’re using yarn, it’s similar. Refer to @PowerKiKi’s comment here: https://github.com/GoogleChromeLabs/critters/pull/117#issuecomment-1324699091)
Remove this once a proper fix is out.
(Note that I’ve got Angular 15.0.1, Typescript 4.8.4 and Bootstrap 5.2.3 installed, I’m not using ng-angular but this fix should still work)
Proof:
package.json:Similar issue found on Angular 14. The workaround removed the selector error, but I’m still seeing some other warnings.
Package.json below:
hi @hhubik ,@kmlbdh i am used angular SSR for my project, that running time , i faced this error ‘1 rules skipped due to selector errors: legend+* -> Cannot read property ‘type’ of undefined’
i tried using this code in angualr.json , build object–>configurations–>production section that is not worked for me 😦 if any other place in angular .json to add this code???
“optimization”: { “scripts”: true, “styles”: { “minify”: true, “inlineCritical”: false }, “fonts”: true },
not worked for me
same error for my intial project –>
I also have problems with this… and didn’t found a good solution yet!
I have an Angular app with SSR pre-rendenring.
So I disabled inline Css as suggested many times here on my express node server :
Great, the warnings disappeared!
However, I started having “flickering” on my app loading on the browser…
This thread talks about this flickering problem :
Has been fixed by this one :
inlineCriticalCss: trueto fix it!! 😃So if I put back the
inlineCssCriticaltotrueon server :So it seems I have to choose between :
For now I chose better rendering for the users, because flickering is really a bad user experience…
But I think I miss something, like I can have a “correct” first rendering on the browser for my pre-rendered HTML while having decent rendering time and no errors on logs ?
If you have some ideas, please tell me !
Thanks
It is not an ng-bootstrap issue as it was discussed previously. I didn’t want to close it until it gets resolved with dependencies.
This should have been fixed in
critters@0.0.17→ https://github.com/GoogleChromeLabs/critters/issues/103At least I don’t see this issue anymore using
critters >= 0.0.17and running ng-bootstrap’s SSR tests.So you can either resolve
crittersto this version or use@angular-devkit/build-angular@16.1.0where they’ve bumped critters0.0.16 → 0.0.18:This is the solution in May of 2023 with Angular 16 and Bootstrap 5.
That has worked for me as well. I use Angular 15.2.0 with the latest gratest libraries for SSR as well and Bootstrap 5.2.3
I’m having the same issue, but I don’t think it’s a bug in ng-bootstrap or bootstrap. This particular warning (when not disabling it setting inlineCritical to false) is thrown when combining an adjacent sibling with a universal selector. In Bootstrap’s case this used for clearing elements in the Legend element, but this warning will be shown whenever you use the combination. However i think it is perfectly valid css.
E.g. having this CSS in your an Angular app will thrown the same warning:
Worked for me optimization [https://angular.io/guide/workspace-config#optimization-configuration]
Same for me
Integration Angular Universal to my project for SSR. But I have this issue even after I corrected the suggested correction in Anguşar.json.
The root issue is not in this package, but in
critters, over there: https://github.com/GoogleChromeLabs/critters/issues/103@gravityctrl can you please close this issue and, if needed, keep the conversation in the other thread please ?
Is there any news on how to solve this? I’m finding it difficult to develop my frontend app with ng serve when over half my css won’t load, and I can’t upgrade from Angular 11 since this issue pops up as soon as I upgrade to v12.
@stevewhitmore I only use the grid from from
Bootstrap 5(5.1.3) that I import instyles.csslike thisThis seems to work fine since I have added the fix in the
angular.jsonfile.it didn’t work for me too