@angular/build: source-map comment scanner corrupts valid JS containing a regex literal
維護者通常 1 天內回覆
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 76/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- angular, typescript
- 領域
- build-system, devtools
研究方向
The issue identifies removeSourceMappingURL in @angular/build/src/utils/source-map.js and provides a standalone reproduction. Start by running the reproduction against the affected package version, then inspect the scanner and the related fix in PR #33545. Done means source-map removal preserves the given valid JavaScript and the reproduction assertion passes.
由索引模型根據 Issue 內容生成。
描述
Command
serve
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
@angular/build 22.0.9 passes the isolated source-map removal test. @angular/cli remains at 22.2.4; Angular framework packages remain at 22.2.3.
Description
With @angular/build 22.2.4, ng serve fails when optimization and script
source maps are enabled. Vite reports invalid JavaScript during import
analysis. However, ng build succeeds, and the built application worked
when served separately using a local static server.
The failure was traced to removeSourceMappingURL in @angular/build.
The development-server memory plugin calls this function before handing
generated JavaScript to Vite when a source map is present.
The scanner appears to interpret a double quote inside a valid
regular-expression literal as the beginning of a string. It then loses
track of the actual string boundaries and removes a sourceMappingURL-like
sequence that is string content, not a JavaScript comment.
This can be reproduced directly using the published build package,
without application code, authentication libraries, or Vite itself.
Expected:
Source-map comment removal preserves valid JavaScript, including
regular-expression literals and strings containing sourceMappingURL text.
Actual:
Valid JavaScript is truncated into invalid JavaScript. Vite subsequently
reports the parsing error.
The desired behavior is to keep both optimization and script source maps
enabled.
Minimal Reproduction
With @angular/[email protected] installed, save the following as repro.cjs
and run:
node repro.cjs
This intentionally calls the internal utility to isolate the defect.
It is a standalone scanner reproduction, not a complete Angular app.
const assert = require('node:assert/strict');
const path = require('node:path');
const vm = require('node:vm');
const packageRoot = path.dirname(
require.resolve('@angular/build/package.json')
);
const { removeSourceMappingURL } = require(
path.join(packageRoot, 'src', 'utils', 'source-map.js')
);
const input =
'const pattern = /"/; const text = "//# sourceMappingURL=not-a-comment";';
new vm.Script(input); // The input is valid JavaScript.
const output = removeSourceMappingURL(input);
console.log(output);
assert.equal(
output,
input,
'Input without an actual source-map comment should remain unchanged'
);
Expected:
The assertion passes and the input is preserved unchanged.
Actual:
The assertion fails. The output is:
const pattern = /"/; const text = "
The output is invalid JavaScript. The sourceMappingURL text was inside
a quoted string, not an actual comment.
Exception or Error
[vite] Internal server error: Failed to parse source for import analysis
because the content contains invalid JS syntax. If you are using JSX,
make sure to name the file with the .jsx or .tsx extension.
Plugin: vite:import-analysis
The standalone reproduction fails its equality assertion.
Parsing the truncated output also produces:
SyntaxError: Invalid or unexpected token
Your Environment
Original failing environment:
@angular/build: 22.2.4
@angular/cli: 22.2.4
@angular/core: 22.2.3
@angular/compiler: 22.2.3
@angular/compiler-cli: 22.2.3
TypeScript: 6.0.3
Vite: 8.3.0
Node.js: 24.20.0
OS: Windows
Current version-pin configuration:
@angular/build: 22.0.9
@angular/cli: 22.2.4 — unchanged
Angular core/compiler/compiler-cli: 22.2.3 — unchanged
Vite resolved by @angular/build: 7.3.6
Anything else relevant?
Temporary workaround applied
Pinned @angular/build to exactly 22.0.9 instead of 22.2.4:
"@angular/build": "22.0.9"
This is the workaround currently used, not a fix to the scanner.
@angular/cliremains at22.2.4— it was not downgraded.- Angular core/compiler/compiler-cli remain at
22.2.3. - Optimization and script source maps remain enabled.
The pinned build package uses Vite 7.3.6 instead of 8.3.0.
However, the minimal reproduction demonstrates the corruption directly
in @angular/build's source-map scanner without invoking Vite.
Related issue and fix
- Issue #33544 — Source-map comment removal corrupts JavaScript inside template literals
- PR #33545 — Prevent stripping nested sourceMappingURL comments
The earlier issue concerned source-map text inside template literals.
Its fix introduced the replacement scanner. This report concerns
regular-expression literal handling in that scanner.
- 主要語言
- TypeScript
- 星號
- 27k
- 分支
- 11.8k
- 平均合併
- 1 天 34 分鐘
- 30 天內合併 PR
- 275
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
angular/angular-cli 的其他 Issue
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-server可能已有人在做 @alan-agius4 於 4 天前認領。 未關閉area: @angular/build gemini-triaged
難度 2/5 1-3 小時 新手友好度 74/100
angular/angular-cli#33955 ·
維護者通常 1 天內回覆
-
pnpm add and pnpm install fail after ng new on pnpm 11+ (ERR_PNPM_IGNORED_BUILDS)可能已有人在做 @alan-agius4 於 1 天前認領。 未關閉area: @angular/cli
難度 3/5 1-2 天 新手友好度 48/100
angular/angular-cli#34622 ·
維護者通常 1 天內回覆
-
Tailwind CSS v4 classes in new or moved files are not picked up by ng serve until another rebuild可能重新可做 關聯的 PR 已關閉且未合併。 未關閉area: @angular/build
難度 4/5 3-5 天 新手友好度 35/100
angular/angular-cli#34446 ·
維護者通常 1 天內回覆
-
area: @angular/build
難度 4/5 3-5 天 新手友好度 58/100
angular/angular-cli#34396 ·
維護者通常 1 天內回覆
-
area: @angular/build
難度 4/5 3-5 天 新手友好度 48/100
angular/angular-cli#34262 ·
維護者通常 1 天內回覆
查看 angular/angular-cli 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 83/100
維護者通常 1 天內回覆
-
🔊 a11y
難度 2/5 1-3 小時 新手友好度 82/100
betagouv/mon-entreprise#4726 ·
維護者通常 9 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
Deltares/fews-pi-requests#357 ·
維護者通常 1 天內回覆
-
bug confirmed js v6
難度 2/5 1-3 小時 新手友好度 85/100
維護者通常 1 天內回覆