Title: @angular/build: source-map comment scanner corrupts valid JS containing a regex literal · Issue #34590 · angular/angular-cli · GitHub
Open Graph Title: @angular/build: source-map comment scanner corrupts valid JS containing a regex literal · Issue #34590 · angular/angular-cli
X Title: @angular/build: source-map comment scanner corrupts valid JS containing a regex literal · Issue #34590 · angular/angular-cli
Description: 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 remain...
Open Graph Description: 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 sour...
X Description: 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 sour...
Opengraph URL: https://github.com/angular/angular-cli/issues/34590
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"@angular/build: source-map comment scanner corrupts valid JS containing a regex literal","articleBody":"### Command\n\nserve\n\n### Is this a regression?\n\n- [x] Yes, this behavior used to work in the previous version\n\n### The previous version in which this bug was not present was\n\n@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.\n\n### Description\n\nWith @angular/build 22.2.4, ng serve fails when optimization and script\nsource maps are enabled. Vite reports invalid JavaScript during import\nanalysis. However, ng build succeeds, and the built application worked\nwhen served separately using a local static server.\n\nThe failure was traced to removeSourceMappingURL in @angular/build.\nThe development-server memory plugin calls this function before handing\ngenerated JavaScript to Vite when a source map is present.\n\nThe scanner appears to interpret a double quote inside a valid\nregular-expression literal as the beginning of a string. It then loses\ntrack of the actual string boundaries and removes a sourceMappingURL-like\nsequence that is string content, not a JavaScript comment.\n\nThis can be reproduced directly using the published build package,\nwithout application code, authentication libraries, or Vite itself.\n\nExpected:\nSource-map comment removal preserves valid JavaScript, including\nregular-expression literals and strings containing sourceMappingURL text.\n\nActual:\nValid JavaScript is truncated into invalid JavaScript. Vite subsequently\nreports the parsing error.\n\nThe desired behavior is to keep both optimization and script source maps\nenabled.\n\n### Minimal Reproduction\n\nWith `@angular/build@22.2.4` installed, save the following as `repro.cjs`\nand run:\n\n```sh\nnode repro.cjs\n```\n\nThis intentionally calls the internal utility to isolate the defect.\nIt is a standalone scanner reproduction, not a complete Angular app.\n\n```js\nconst assert = require('node:assert/strict');\nconst path = require('node:path');\nconst vm = require('node:vm');\n\nconst packageRoot = path.dirname(\n require.resolve('@angular/build/package.json')\n);\n\nconst { removeSourceMappingURL } = require(\n path.join(packageRoot, 'src', 'utils', 'source-map.js')\n);\n\nconst input =\n 'const pattern = /\"/; const text = \"//# sourceMappingURL=not-a-comment\";';\n\nnew vm.Script(input); // The input is valid JavaScript.\n\nconst output = removeSourceMappingURL(input);\nconsole.log(output);\n\nassert.equal(\n output,\n input,\n 'Input without an actual source-map comment should remain unchanged'\n);\n```\n\nExpected:\nThe assertion passes and the input is preserved unchanged.\n\nActual:\nThe assertion fails. The output is:\n\n```js\nconst pattern = /\"/; const text = \"\n```\n\nThe output is invalid JavaScript. The `sourceMappingURL` text was inside\na quoted string, not an actual comment.\n\n### Exception or Error\n\n```text\n[vite] Internal server error: Failed to parse source for import analysis\nbecause the content contains invalid JS syntax. If you are using JSX,\nmake sure to name the file with the .jsx or .tsx extension.\nPlugin: vite:import-analysis\n\nThe standalone reproduction fails its equality assertion.\nParsing the truncated output also produces:\nSyntaxError: Invalid or unexpected token\n```\n\n### Your Environment\n\n```text\nOriginal failing environment:\n@angular/build: 22.2.4\n@angular/cli: 22.2.4\n@angular/core: 22.2.3\n@angular/compiler: 22.2.3\n@angular/compiler-cli: 22.2.3\nTypeScript: 6.0.3\nVite: 8.3.0\nNode.js: 24.20.0\nOS: Windows\n\nCurrent version-pin configuration:\n@angular/build: 22.0.9\n@angular/cli: 22.2.4 — unchanged\nAngular core/compiler/compiler-cli: 22.2.3 — unchanged\nVite resolved by @angular/build: 7.3.6\n```\n\n### Anything else relevant?\n\n### Temporary workaround applied\n\nPinned `@angular/build` to exactly `22.0.9` instead of `22.2.4`:\n\n\"@angular/build\": \"22.0.9\"\n\nThis is the workaround currently used, not a fix to the scanner.\n\n- `@angular/cli` remains at `22.2.4` — it was not downgraded.\n- Angular core/compiler/compiler-cli remain at `22.2.3`.\n- Optimization and script source maps remain enabled.\n\nThe pinned build package uses Vite `7.3.6` instead of `8.3.0`.\nHowever, the minimal reproduction demonstrates the corruption directly\nin `@angular/build`'s source-map scanner without invoking Vite.\n\n\n### Related issue and fix\n\n- [Issue #33544 — Source-map comment removal corrupts JavaScript inside template literals](https://github.com/angular/angular-cli/issues/33544)\n- [PR #33545 — Prevent stripping nested sourceMappingURL comments](https://github.com/angular/angular-cli/pull/33545)\n\nThe earlier issue concerned source-map text inside template literals.\nIts fix introduced the replacement scanner. This report concerns\nregular-expression literal handling in that scanner.","author":{"url":"https://github.com/monyk99","@type":"Person","name":"monyk99"},"datePublished":"2026-10-29T14:01:32Z","url":"https://github.com/angular/angular-cli/issues/34590"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1fc1c37d-8541-3156-1ec6-c7c6d2f0c3e7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C8C6:29FFA9:11DCE03:16AE6E7:6B011A94 |
| html-safe-nonce | 21b203455f59e9602ae3014d34a15dcd1b676d0e36170f57091002a52556ab24 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOEM2OjI5RkZBOToxMURDRTAzOjE2QUU2RTc6NkIwMTFBOTQiLCJ2aXNpdG9yX2lkIjoiNDU1NDMxMDkzNTA5NDgyNzY2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 691f6d14502a0e7f7dbf4355f37712583bf607cecc6e4b666679c9b8fb769dd9 |
| hovercard-subject-tag | issue:6101288920 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/34590/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e36e33dc9929663a8d546f6de520f73d8878f2d23b63751cfdef8898315ccdbb/angular/angular-cli/issues/34590 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e36e33dc9929663a8d546f6de520f73d8878f2d23b63751cfdef8898315ccdbb/angular/angular-cli/issues/34590 |
| og:image:alt | 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 sour... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | monyk99 |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width