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 when …
…using vitedev server with prerendering and ssr This commit improves the printed error messages when using Vite with SSR and/or SSG by doing a couple of things. - Enabling resolving and loading of sourcemap in Node.js by using `process.setSourceMapsEnabled`. See https://nodejs.org/api/process.html#processsetsourcemapsenabledval - Amends Vite's `ssrTransform` method to remap the sourcemaps and inlines them. - Enables `__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION` Zone.js flag to output cleaner stacktraces. To enable, the above mentioned zone.js flag we had to create a server polyfill bundle as otherwise in some cases, zone.js would have been split and loaded before the flag. Before ``` ERROR ReferenceError: window is not defined at console (/src/app/app.component.ts:19:11) at NodeInjectorFactory.AppComponent_Factory (/src/app/app.component.ts:12:26) at getNodeInjectable (/usr/local/xxx/packages/core/src/render3/di.ts:659:38) at createRootComponent (/usr/local/xxx/packages/core/src/render3/component_ref.ts:464:31) at ComponentFactory.create (/usr/local/xxx/packages/core/src/render3/component_ref.ts:288:19) at ApplicationRef.bootstrap (/usr/local/xxx/packages/core/src/application_ref.ts:1017:38) at <anonymous> (/usr/local/xxx/packages/core/src/application_ref.ts:287:20) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:368:26) at Object.onInvoke (/usr/local/xxx/packages/core/src/zone/ng_zone.ts:443:29) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:367:52) ERROR Error: Uncaught (in promise): ReferenceError: window is not defined ReferenceError: window is not defined at console (/src/app/app.component.ts:19:11) at NodeInjectorFactory.AppComponent_Factory (/src/app/app.component.ts:12:26) at getNodeInjectable (/usr/local/xxx/packages/core/src/render3/di.ts:659:38) at createRootComponent (/usr/local/xxx/packages/core/src/render3/component_ref.ts:464:31) at ComponentFactory.create (/usr/local/xxx/packages/core/src/render3/component_ref.ts:288:19) at ApplicationRef.bootstrap (/usr/local/xxx/packages/core/src/application_ref.ts:1017:38) at <anonymous> (/usr/local/xxx/packages/core/src/application_ref.ts:287:20) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:368:26) at Object.onInvoke (/usr/local/xxx/packages/core/src/zone/ng_zone.ts:443:29) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:367:52) at resolvePromise (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:1124:31) at /usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:1195:17 at _ZoneDelegate.invokeTask (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:402:31) at AsyncStackTaggingZoneSpec.onInvokeTask (/usr/local/xxx/packages/core/src/zone/async-stack-tagging.ts:46:22) at _ZoneDelegate.invokeTask (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:401:60) at Object.onInvokeTask (/usr/local/xxx/packages/core/src/zone/ng_zone.ts:428:29) at _ZoneDelegate.invokeTask (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:401:60) at Zone.runTask (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:173:47) at drainMicroTaskQueue (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:581:35) { rejection: ReferenceError: window is not defined at console (/src/app/app.component.ts:19:11) at NodeInjectorFactory.AppComponent_Factory (/src/app/app.component.ts:12:26) at getNodeInjectable (/usr/local/xxx/packages/core/src/render3/di.ts:659:38) at createRootComponent (/usr/local/xxx/packages/core/src/render3/component_ref.ts:464:31) at ComponentFactory.create (/usr/local/xxx/packages/core/src/render3/component_ref.ts:288:19) at ApplicationRef.bootstrap (/usr/local/xxx/packages/core/src/application_ref.ts:1017:38) at <anonymous> (/usr/local/xxx/packages/core/src/application_ref.ts:287:20) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:368:26) at Object.onInvoke (/usr/local/xxx/packages/core/src/zone/ng_zone.ts:443:29) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:367:52), promise: ZoneAwarePromise [Promise] { __zone_symbol__state: 0, __zone_symbol__value: ReferenceError: window is not defined at console (/src/app/app.component.ts:19:11) at NodeInjectorFactory.AppComponent_Factory (/src/app/app.component.ts:12:26) at getNodeInjectable (/usr/local/xxx/packages/core/src/render3/di.ts:659:38) at createRootComponent (/usr/local/xxx/packages/core/src/render3/component_ref.ts:464:31) at ComponentFactory.create (/usr/local/xxx/packages/core/src/render3/component_ref.ts:288:19) at ApplicationRef.bootstrap (/usr/local/xxx/packages/core/src/application_ref.ts:1017:38) at <anonymous> (/usr/local/xxx/packages/core/src/application_ref.ts:287:20) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:368:26) at Object.onInvoke (/usr/local/xxx/packages/core/src/zone/ng_zone.ts:443:29) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:367:52) }, zone: <ref *1> Zone { _parent: Zone { _parent: [Zone], _name: 'asyncStackTagging for Angular', _properties: {}, _zoneDelegate: [_ZoneDelegate] }, _name: 'angular', _properties: { isAngularZone: true }, _zoneDelegate: <ref *2> _ZoneDelegate { _taskCounts: [Object], zone: [Circular *1], _parentDelegate: [_ZoneDelegate], _forkZS: null, _forkDlgt: null, _forkCurrZone: null, _interceptZS: null, _interceptDlgt: null, _interceptCurrZone: null, _invokeZS: [Object], _invokeDlgt: [_ZoneDelegate], _invokeCurrZone: [Circular *1], _handleErrorZS: [Object], _handleErrorDlgt: [_ZoneDelegate], _handleErrorCurrZone: [Circular *1], _scheduleTaskZS: [Object], _scheduleTaskDlgt: [_ZoneDelegate], _scheduleTaskCurrZone: [Circular *1], _invokeTaskZS: [Object], _invokeTaskDlgt: [_ZoneDelegate], _invokeTaskCurrZone: [Circular *1], _cancelTaskZS: [Object], _cancelTaskDlgt: [_ZoneDelegate], _cancelTaskCurrZone: [Circular *1], _hasTaskZS: [Object], _hasTaskDlgt: [_ZoneDelegate], _hasTaskDlgtOwner: [Circular *2], _hasTaskCurrZone: [Circular *1] 6:22:33 AM [vite] Internal server error: window is not defined at console (/src/app/app.component.ts:19:11) at NodeInjectorFactory.AppComponent_Factory (/src/app/app.component.ts:12:26) at getNodeInjectable (/usr/local/xxx/packages/core/src/render3/di.ts:659:38) at createRootComponent (/usr/local/xxx/packages/core/src/render3/component_ref.ts:464:31) at ComponentFactory.create (/usr/local/xxx/packages/core/src/render3/component_ref.ts:288:19) at ApplicationRef.bootstrap (/usr/local/xxx/packages/core/src/application_ref.ts:1017:38) at <anonymous> (/usr/local/xxx/packages/core/src/application_ref.ts:287:20) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:368:26) at Object.onInvoke (/usr/local/xxx/packages/core/src/zone/ng_zone.ts:443:29) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:367:52) ERROR ReferenceError: window is not defined at console (/src/app/app.component.ts:19:11) at NodeInjectorFactory.AppComponent_Factory (/src/app/app.component.ts:12:26) at getNodeInjectable (/usr/local/xxx/packages/core/src/render3/di.ts:659:38) at createRootComponent (/usr/local/xxx/packages/core/src/render3/component_ref.ts:464:31) at ComponentFactory.create (/usr/local/xxx/packages/core/src/render3/component_ref.ts:288:19) at ApplicationRef.bootstrap (/usr/local/xxx/packages/core/src/application_ref.ts:1017:38) at <anonymous> (/usr/local/xxx/packages/core/src/application_ref.ts:287:20) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:368:26) at Object.onInvoke (/usr/local/xxx/packages/core/src/zone/ng_zone.ts:443:29) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:367:52) ERROR Error: Uncaught (in promise): ReferenceError: window is not defined ReferenceError: window is not defined at console (/src/app/app.component.ts:19:11) at NodeInjectorFactory.AppComponent_Factory (/src/app/app.component.ts:12:26) at getNodeInjectable (/usr/local/xxx/packages/core/src/render3/di.ts:659:38) at createRootComponent (/usr/local/xxx/packages/core/src/render3/component_ref.ts:464:31) at ComponentFactory.create (/usr/local/xxx/packages/core/src/render3/component_ref.ts:288:19) at ApplicationRef.bootstrap (/usr/local/xxx/packages/core/src/application_ref.ts:1017:38) at <anonymous> (/usr/local/xxx/packages/core/src/application_ref.ts:287:20) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:368:26) at Object.onInvoke (/usr/local/xxx/packages/core/src/zone/ng_zone.ts:443:29) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:367:52) at resolvePromise (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:1124:31) at /usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:1195:17 at _ZoneDelegate.invokeTask (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:402:31) at AsyncStackTaggingZoneSpec.onInvokeTask (/usr/local/xxx/packages/core/src/zone/async-stack-tagging.ts:46:22) at _ZoneDelegate.invokeTask (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:401:60) at Object.onInvokeTask (/usr/local/xxx/packages/core/src/zone/ng_zone.ts:428:29) at _ZoneDelegate.invokeTask (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:401:60) at Zone.runTask (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:173:47) at drainMicroTaskQueue (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:581:35) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { rejection: ReferenceError: window is not defined at console (/src/app/app.component.ts:19:11) at NodeInjectorFactory.AppComponent_Factory (/src/app/app.component.ts:12:26) at getNodeInjectable (/usr/local/xxx/packages/core/src/render3/di.ts:659:38) at createRootComponent (/usr/local/xxx/packages/core/src/render3/component_ref.ts:464:31) at ComponentFactory.create (/usr/local/xxx/packages/core/src/render3/component_ref.ts:288:19) at ApplicationRef.bootstrap (/usr/local/xxx/packages/core/src/application_ref.ts:1017:38) at <anonymous> (/usr/local/xxx/packages/core/src/application_ref.ts:287:20) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:368:26) at Object.onInvoke (/usr/local/xxx/packages/core/src/zone/ng_zone.ts:443:29) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:367:52), promise: ZoneAwarePromise [Promise] { __zone_symbol__state: 0, __zone_symbol__value: ReferenceError: window is not defined at console (/src/app/app.component.ts:19:11) at NodeInjectorFactory.AppComponent_Factory (/src/app/app.component.ts:12:26) at getNodeInjectable (/usr/local/xxx/packages/core/src/render3/di.ts:659:38) at createRootComponent (/usr/local/xxx/packages/core/src/render3/component_ref.ts:464:31) at ComponentFactory.create (/usr/local/xxx/packages/core/src/render3/component_ref.ts:288:19) at ApplicationRef.bootstrap (/usr/local/xxx/packages/core/src/application_ref.ts:1017:38) at <anonymous> (/usr/local/xxx/packages/core/src/application_ref.ts:287:20) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:368:26) at Object.onInvoke (/usr/local/xxx/packages/core/src/zone/ng_zone.ts:443:29) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:367:52) }, zone: <ref *1> Zone { _parent: Zone { _parent: [Zone], _name: 'asyncStackTagging for Angular', _properties: {}, _zoneDelegate: [_ZoneDelegate] }, _name: 'angular', _properties: { isAngularZone: true }, _zoneDelegate: <ref *2> _ZoneDelegate { _taskCounts: [Object], zone: [Circular *1], _parentDelegate: [_ZoneDelegate], _forkZS: null, _forkDlgt: null, _forkCurrZone: null, _interceptZS: null, _interceptDlgt: null, _interceptCurrZone: null, _invokeZS: [Object], _invokeDlgt: [_ZoneDelegate], _invokeCurrZone: [Circular *1], _handleErrorZS: [Object], _handleErrorDlgt: [_ZoneDelegate], _handleErrorCurrZone: [Circular *1], _scheduleTaskZS: [Object], _scheduleTaskDlgt: [_ZoneDelegate], _scheduleTaskCurrZone: [Circular *1], _invokeTaskZS: [Object], _invokeTaskDlgt: [_ZoneDelegate], _invokeTaskCurrZone: [Circular *1], _cancelTaskZS: [Object], _cancelTaskDlgt: [_ZoneDelegate], _cancelTaskCurrZone: [Circular *1], _hasTaskZS: [Object], _hasTaskDlgt: [_ZoneDelegate], _hasTaskDlgtOwner: [Circular *2], _hasTaskCurrZone: [Circular *1] } }, 6:23:04 AM [vite] Internal server error: window is not defined at console (/src/app/app.component.ts:19:11) at NodeInjectorFactory.AppComponent_Factory (/src/app/app.component.ts:12:26) at getNodeInjectable (/usr/local/xxx/packages/core/src/render3/di.ts:659:38) at createRootComponent (/usr/local/xxx/packages/core/src/render3/component_ref.ts:464:31) at ComponentFactory.create (/usr/local/xxx/packages/core/src/render3/component_ref.ts:288:19) at ApplicationRef.bootstrap (/usr/local/xxx/packages/core/src/application_ref.ts:1017:38) at <anonymous> (/usr/local/xxx/packages/core/src/application_ref.ts:287:20) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:368:26) at Object.onInvoke (/usr/local/xxx/packages/core/src/zone/ng_zone.ts:443:29) at _ZoneDelegate.invoke (/usr/local/xxx/cli-reproduction/test-ssr-/node_modules/zone.js/fesm2015/zone-node.js:367:52) ``` After ``` ERROR ReferenceError: window is not defined at console (/src/app/app.component.ts:17:3) at NodeInjectorFactory.AppComponent_Factory (/src/app/app.component.ts:12:26) at getNodeInjectable (/usr/local/xxx/git/packages/core/src/render3/di.ts:659:38) at createRootComponent (/usr/local/xxx/git/packages/core/src/render3/component_ref.ts:464:31) at ComponentFactory.create (/usr/local/xxx/git/packages/core/src/render3/component_ref.ts:288:19) at ApplicationRef.bootstrap (/usr/local/xxx/git/packages/core/src/application_ref.ts:1017:38) at <anonymous> (/usr/local/xxx/git/packages/core/src/application_ref.ts:287:20) at _ZoneDelegate.invoke (/node_modules/zone.js/fesm2015/zone-node.js:370:40) at Object.onInvoke (/usr/local/xxx/git/packages/core/src/zone/ng_zone.ts:443:29) at _ZoneDelegate.invoke (/node_modules/zone.js/fesm2015/zone-node.js:370:40) ERROR ReferenceError: window is not defined at console (/src/app/app.component.ts:17:3) at NodeInjectorFactory.AppComponent_Factory (/src/app/app.component.ts:12:26) at getNodeInjectable (/usr/local/xxx/git/packages/core/src/render3/di.ts:659:38) at createRootComponent (/usr/local/xxx/git/packages/core/src/render3/component_ref.ts:464:31) at ComponentFactory.create (/usr/local/xxx/git/packages/core/src/render3/component_ref.ts:288:19) at ApplicationRef.bootstrap (/usr/local/xxx/git/packages/core/src/application_ref.ts:1017:38) at <anonymous> (/usr/local/xxx/git/packages/core/src/application_ref.ts:287:20) at _ZoneDelegate.invoke (/node_modules/zone.js/fesm2015/zone-node.js:370:40) at Object.onInvoke (/usr/local/xxx/git/packages/core/src/zone/ng_zone.ts:443:29) at _ZoneDelegate.invoke (/node_modules/zone.js/fesm2015/zone-node.js:370:40) 8:13:37 AM [vite] Internal server error: window is not defined at console (/src/app/app.component.ts:17:3) at NodeInjectorFactory.AppComponent_Factory (/src/app/app.component.ts:12:26) at getNodeInjectable (/usr/local/xxx/git/packages/core/src/render3/di.ts:659:38) at createRootComponent (/usr/local/xxx/git/packages/core/src/render3/component_ref.ts:464:31) at ComponentFactory.create (/usr/local/xxx/git/packages/core/src/render3/component_ref.ts:288:19) at ApplicationRef.bootstrap (/usr/local/xxx/git/packages/core/src/application_ref.ts:1017:38) at <anonymous> (/usr/local/xxx/git/packages/core/src/application_ref.ts:287:20) at _ZoneDelegate.invoke (/node_modules/zone.js/fesm2015/zone-node.js:370:40) at Object.onInvoke (/usr/local/xxx/git/packages/core/src/zone/ng_zone.ts:443:29) at _ZoneDelegate.invoke (/node_modules/zone.js/fesm2015/zone-node.js:370:40) ``` Note: in the above case the error is printed 3x, this will be addressed in the future.
- Loading branch information