-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular-devkit/build-angular): resolve and load sourcemaps durin…
…g prerendering to provide better stacktraces With this commit when running a build with sourcemaps enabled we enable Node.js Sourcemap support for stack traces. See: https://nodejs.org/dist/latest/docs/api/cli.html#--enable-source-maps for more information about this feature. Before ``` ERROR ReferenceError: window is not defined at new _AppComponent (file:///chunk-HFZN2HE2.mjs:41631:19) at NodeInjectorFactory.AppComponent_Factory [as factory] (file:///chunk-HFZN2HE2.mjs:41635:12) at getNodeInjectable (file:///chunk-HFZN2HE2.mjs:6104:38) at createRootComponent (file:///chunk-HFZN2HE2.mjs:10446:31) at ComponentFactory.create (file:///chunk-HFZN2HE2.mjs:10348:19) at _ApplicationRef.bootstrap (file:///chunk-HFZN2HE2.mjs:13247:40) at file:///chunk-HFZN2HE2.mjs:12938:20 at _ZoneDelegate.invoke (file:///chunk-HFZN2HE2.mjs:320:158) at Object.onInvoke (file:///chunk-HFZN2HE2.mjs:8562:25) at _ZoneDelegate.invoke (file:///chunk-HFZN2HE2.mjs:320:46) ``` Now ``` ERROR ReferenceError: window is not defined at constructor (/usr/xxxx/src/app/app.component.ts:16:17) at NodeInjectorFactory.AppComponent_Factory (/usr/xxxx/src/app/app.component.ts:17:3) at getNodeInjectable (/usr/xxxx/node_modules/@angular/core/fesm2022/core.mjs:4166:38) at createRootComponent (/usr/xxxx/node_modules/@angular/core/fesm2022/core.mjs:14064:31) at ComponentFactory.create (/usr/xxxx/node_modules/@angular/core/fesm2022/core.mjs:13931:19) at _ApplicationRef.bootstrap (/usr/xxxx/node_modules/@angular/core/fesm2022/core.mjs:30650:40) at <anonymous> (/usr/xxxx/node_modules/@angular/core/fesm2022/core.mjs:30163:20) at _ZoneDelegate.invoke (/usr/xxxx/node_modules/zone.js/fesm2015/zone-node.js:344:158) at Object.onInvoke (/usr/xxxx/node_modules/@angular/core/fesm2022/core.mjs:10964:25) at _ZoneDelegate.invoke (/usr/xxxx/node_modules/zone.js/fesm2015/zone-node.js:344:46) ``` Closes #26013 (cherry picked from commit 0f45e21)
- Loading branch information
1 parent
52f5956
commit 263271f
Showing
3 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tests/legacy-cli/e2e/tests/build/prerender/error-with-sourcemaps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ng } from '../../../utils/process'; | ||
import { getGlobalVariable } from '../../../utils/env'; | ||
import { rimraf, writeMultipleFiles } from '../../../utils/fs'; | ||
import { match } from 'node:assert'; | ||
import { expectToFail } from '../../../utils/utils'; | ||
|
||
export default async function () { | ||
const useWebpackBuilder = !getGlobalVariable('argv')['esbuild']; | ||
if (useWebpackBuilder) { | ||
return; | ||
} | ||
|
||
// Forcibly remove in case another test doesn't clean itself up. | ||
await rimraf('node_modules/@angular/ssr'); | ||
await ng('add', '@angular/ssr', '--skip-confirmation'); | ||
|
||
await writeMultipleFiles({ | ||
'src/app/app.component.ts': ` | ||
import { Component } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { RouterOutlet } from '@angular/router'; | ||
@Component({ | ||
selector: 'app-root', | ||
standalone: true, | ||
imports: [CommonModule, RouterOutlet], | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.css'] | ||
}) | ||
export class AppComponent { | ||
title = 'test-ssr'; | ||
constructor() { | ||
console.log(window) | ||
} | ||
} | ||
`, | ||
}); | ||
|
||
const { message } = await expectToFail(() => | ||
ng('build', '--configuration', 'development', '--prerender'), | ||
); | ||
match(message, /window is not defined[.\s\S]*constructor \(.*app\.component\.ts\:\d+:\d+\)/); | ||
} |