@angular/build: source-map comment scanner corrupts valid JS containing a regex literal
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 76/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- angular, typescript
- Domínio
- build-system, devtools
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- TypeScript
- Estrelas
- 27k
- Forks
- 11.8k
- Merge médio
- 1d 2h
- PRs com merge (30d)
- 292
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de angular/angular-cli
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-serverTalvez já em andamento @alan-agius4 assumiu há 1 dia. Abertaarea: @angular/build gemini-triaged
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
angular/angular-cli#33955 ·
Mantenedores costumam responder em até 1 dia
-
build: ERR_REQUIRE_CYCLE_MODULE when loading oxc-parser in StackBlitz / WebContainerTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Abertaarea: @angular/build
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
angular/angular-cli#34524 · 5 comentários · 2 reações ·
Mantenedores costumam responder em até 1 dia
-
Tailwind CSS v4 classes in new or moved files are not picked up by ng serve until another rebuildTalvez já em andamento @MeAkib assumiu há 10 dias. Abertaarea: @angular/build
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
angular/angular-cli#34446 ·
Mantenedores costumam responder em até 1 dia
-
area: @angular/build
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 58/100
angular/angular-cli#34396 ·
Mantenedores costumam responder em até 1 dia
-
Follow-up to issue: SSR: Add a way to configure externalDependencies for the server bundle onlyAbertaarea: @angular/build
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
angular/angular-cli#34262 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de angular/angular-cli
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Northeastern-Electric-Racing/FinishLine#4660 ·
Mantenedores costumam responder em até 2 dias
-
BeOS .json missingAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
mihaip/infinite-mac#475 ·
-
Let TypeScript accept an initial object in ReactiveDictTalvez já em andamento @yograj-vijay-yadav assumiu hoje. Abertabug good first issue help wanted workshop
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 92/100
meteor/meteor#14919 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
marmelab/atomic-crm#401 ·
Mantenedores costumam responder em até 1 dia
-
account: profile
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
Mantenedores costumam responder em até 5 dias