Skip to content

fix(@angular/cli): properly handle Node.js require() errors with ESM modules #30288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/angular/build/src/utils/load-proxy-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function loadProxyConfiguration(
break;
} catch (e) {
assertIsError(e);
if (e.code === 'ERR_REQUIRE_ESM') {
if (e.code === 'ERR_REQUIRE_ESM' || e.code === 'ERR_REQUIRE_ASYNC_MODULE') {
// Load the ESM configuration file using the TypeScript dynamic import workaround.
// Once TypeScript provides support for keeping the dynamic import this workaround can be
// changed to a direct dynamic import.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,10 @@ async function getBuilder(builderPath: string): Promise<any> {
try {
return localRequire(builderPath);
} catch (e) {
if ((e as NodeJS.ErrnoException).code === 'ERR_REQUIRE_ESM') {
if (
(e as NodeJS.ErrnoException).code === 'ERR_REQUIRE_ESM' ||
(e as NodeJS.ErrnoException).code === 'ERR_REQUIRE_ASYNC_MODULE'
) {
// Load the ESM configuration file using the TypeScript dynamic import workaround.
// Once TypeScript provides support for keeping the dynamic import this workaround can be
// changed to a direct dynamic import.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ async function addProxyConfig(
proxyConfiguration = require(proxyPath);
} catch (e) {
assertIsError(e);
if (e.code !== 'ERR_REQUIRE_ESM') {
if (e.code !== 'ERR_REQUIRE_ESM' && e.code !== 'ERR_REQUIRE_ASYNC_MODULE') {
throw e;
}

Expand Down
5 changes: 4 additions & 1 deletion packages/angular_devkit/build_webpack/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ export async function getWebpackConfig(configPath: string): Promise<Configuratio
try {
return require(configPath);
} catch (e) {
if ((e as NodeJS.ErrnoException).code === 'ERR_REQUIRE_ESM') {
if (
(e as NodeJS.ErrnoException).code === 'ERR_REQUIRE_ESM' ||
(e as NodeJS.ErrnoException).code === 'ERR_REQUIRE_ASYNC_MODULE'
) {
// Load the ESM configuration file using the TypeScript dynamic import workaround.
// Once TypeScript provides support for keeping the dynamic import this workaround can be
// changed to a direct dynamic import.
Expand Down