angular / angular/angular-cli

Angular build fails to resolve CSS when package is externalized

Aperta
#30,412 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
angular/build:application area: @angular/build freq1: low severity3: broken
Lingua principale
TypeScript
Stelle
27k
Fork
11.8k
Merge medio
14h 23m
PR unite (30g)
162

Descrizione

### Which @angular/* package(s) are the source of the bug?

compiler

### Is this a regression?

No

### Description

Hi there 👋

In a micro-frontend architecture, our goal is to compile CSS utilities while relying on importmap to load all JavaScript. I'm not sure if I’ve missed a configuration step or if this is expected behavior.

However, in the Vite ecosystem, when using the option to externalize dependencies, all the CSS is correctly resolved, but the JavaScript is excluded from the import.

```js
export default defineConfig((env) => {
return {
build: {
rollupOptions: {
external: ["bootstrap"],
},
},
});
```

However, in the Angular environment, this approach causes the build to fail because it can't locate the CSS.

```json
"projects": {
"test-angular": {
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:application",
"options": {
"externalDependencies": ["bootstrap"],
```

To isolate the issue, I created a minimal reproduction using Bootstrap.

Thank you very much for the awesome work 🚀

### Please provide a link to a minimal reproduction of the bug

https://github.com/Tragio/angular-externalize-repro

### Please provide the exception or error you saw

```true
> ng build

Application bundle generation failed. [1.968 seconds]

✘ [ERROR] Can't find stylesheet to import.

2 │ @use "bootstrap/scss/bootstrap";
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/styles.scss 2:1 root stylesheet [plugin angular-sass]

angular:styles/global:styles:1:8:
1 │ @import 'src/styles.scss';
╵ ~~~~~~~~~~~~~~~~~
```

### Please provide the environment you discovered this bug in (run `ng version`)

```true
Angular CLI: 19.2.14
Node: 22.14.0
Package Manager: npm 10.9.2
OS: darwin arm64

Angular: 19.2.14
... cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1902.14
@angular-devkit/build-angular 19.2.14
@angular-devkit/core 19.2.14
@angular-devkit/schematics 19.2.14
@schematics/angular 19.2.14
rxjs 7.8.2
typescript 5.7.3
zone.js 0.15.1
```

### Anything else?

_No response_

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia dalla riproduzione minima collegata, in particolare da angular.json e src/styles.scss, ed esegui ng build con bootstrap elencato in externalDependencies. Traccia il modo in cui le dipendenze esternalizzate vengono gestite durante la build Sass/stili globali di Angular; il lavoro è completato quando JavaScript rimane esterno mentre bootstrap/scss/bootstrap viene risolto correttamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
angular, bootstrap, sass
Ambito
build-system
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.