Angular build fails to resolve CSS when package is externalized
- 主要語言
- TypeScript
- 星號
- 27k
- 分支
- 11.8k
- 平均合併
- 14 小時 23 分鐘
- 30 天內合併 PR
- 162
描述
### 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_
貢獻指南
研究方向
從連結的最小重現開始,特別查看 angular.json 和 src/styles.scss,並在 externalDependencies 中列出 bootstrap 後執行 ng build。追蹤 Angular Sass/全域樣式建置期間如何處理外部化相依性;當 JavaScript 仍維持為外部相依性,同時 bootstrap/scss/bootstrap 成功解析時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- angular, bootstrap, sass
- 領域
- build-system
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100