-
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.
refactor(@angular-devkit/build-angular): properly display errors orig…
…inating in ESM loader hooks Currently, errors occurring in ESM loader hooks while using `--import` are not correctly displayed, as they cannot be transferred from the worker to the main thread. Although the error is an instance of Error, it contains non-transferable properties and cannot be transmitted from a worker when --import is used. Consequently, when read outside of the worker, the error object displays as `[Object object]`. To address this issue, we reconstruct the error message. See: #27251 (cherry picked from commit 51debcd)
- Loading branch information
1 parent
de2d050
commit 5707578
Showing
4 changed files
with
38 additions
and
12 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
packages/angular_devkit/build_angular/src/utils/server-rendering/load-esm-from-memory.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,33 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { assertIsError } from '../error'; | ||
import { loadEsmModule } from '../load-esm'; | ||
import { MainServerBundleExports, RenderUtilsServerBundleExports } from './main-bundle-exports'; | ||
|
||
export function loadEsmModuleFromMemory( | ||
path: './main.server.mjs', | ||
): Promise<MainServerBundleExports>; | ||
export function loadEsmModuleFromMemory( | ||
path: './render-utils.server.mjs', | ||
): Promise<RenderUtilsServerBundleExports>; | ||
export function loadEsmModuleFromMemory(path: string): Promise<unknown> { | ||
return loadEsmModule(new URL(path, 'memory://')).catch((e) => { | ||
assertIsError(e); | ||
|
||
// While the error is an 'instanceof Error', it is extended with non transferable properties | ||
// and cannot be transferred from a worker when using `--import`. This results in the error object | ||
// displaying as '[Object object]' when read outside of the worker. Therefore, we reconstruct the error message here. | ||
const error: Error & { code?: string } = new Error(e.message); | ||
error.stack = e.stack; | ||
error.name = e.name; | ||
error.code = e.code; | ||
|
||
throw error; | ||
}); | ||
} |
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
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