Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Migration Fails with Error: require() of ES Module not supported when Migrating from 19 to 20 #30411

Closed
@karwank

Description

@karwank

Which @angular/* package(s) are the source of the bug?

cli

Is this a regression?

Yes

Description

Migration Fails with Error: require() of ES Module not supported when Migrating to Angular 20

Description:

I encountered an issue while attempting to update my Angular project from Angular 19 to Angular 20. During the migration process, the Angular CLI encountered the following error:

Migration failed: require() of ES Module /tmp/angular-cli-packages-BFPht2/node_modules/ora/index.js from /tmp/angular-cli-packages-BFPht2/node_modules/@angular-devkit/schematics/tasks/package-manager/executor.js not supported. Instead change the require of index.js in /tmp/angular-cli-packages-BFPht2/node_modules/@angular-devkit/schematics/tasks/package-manager/executor.js to a dynamic import() which is available in all CommonJS modules.

Steps to Reproduce:

  1. Run the command ng new dealer-client to create a new Angular project.
  2. Notice that this creates the project using Angular 19.2 (despite specifying Angular 20).
  3. Run the command ng update @angular/core@20 @angular/cli@20 to upgrade the Angular CLI and dependencies to version 20.
  4. During the migration process, the error is triggered when the migration reaches the step for updating application projects to the new build system.

Expected Behavior:

The update and migration process should complete successfully without errors, including any optional migration tasks like updating the build system.

Actual Behavior:

The migration fails with the following error message:

Migration failed: require() of ES Module /tmp/angular-cli-packages-BFPht2/node_modules/ora/index.js from /tmp/angular-cli-packages-BFPht2/node_modules/@angular-devkit/schematics/tasks/package-manager/executor.js not supported.

Possible Cause:

The error seems related to the attempt to require() an ES module (ora/index.js) from a CommonJS context. It appears that the current migration process might not be fully compatible with ES modules, which causes the failure.

Additional Notes:

  • This issue may be related to specific Node.js versions or dependency versions, so any additional insights into handling ES module compatibility in the migration process would be helpful.
  • I have attempted to perform the migration using both a clean setup and an existing project, with the same result.

Please provide a link to a minimal reproduction of the bug

Select the migrations that you'd like to run [use-application-builder] Migrate application projects to the new build system. (https://angular.dev/tools/cli/build-system-migration)

❯ Migrate application projects to the new build system.
  Application projects that are using the '@angular-devkit/build-angular' package's 'browser' and/or 'browser-esbuild' builders will be migrated to use the new 'application' builder.
  You can read more about this, including known issues and limitations, here: https://angular.dev/tools/cli/build-system-migration
UPDATE package.json (1231 bytes)
UPDATE angular.json (3470 bytes)
UPDATE tsconfig.json (915 bytes)
✖ Migration failed: require() of ES Module /tmp/angular-cli-packages-BFPht2/node_modules/ora/index.js from /tmp/angular-cli-packages-BFPht2/node_modules/@angular-devkit/schematics/tasks/package-manager/executor.js not supported.
Instead change the require of index.js in /tmp/angular-cli-packages-BFPht2/node_modules/@angular-devkit/schematics/tasks/package-manager/executor.js to a dynamic import() which is available in all CommonJS modules.
  See "/tmp/ng-iTS7k7/angular-errors.log" for further details.

Please provide the exception or error you saw

[error] Error [ERR_REQUIRE_ESM]: require() of ES Module /tmp/angular-cli-packages-BFPht2/node_modules/ora/index.js from /tmp/angular-cli-packages-BFPht2/node_modules/@angular-devkit/schematics/tasks/package-manager/executor.js not supported.
Instead change the require of index.js in /tmp/angular-cli-packages-BFPht2/node_modules/@angular-devkit/schematics/tasks/package-manager/executor.js to a dynamic import() which is available in all CommonJS modules.
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at Object.<anonymous> (/tmp/angular-cli-packages-BFPht2/node_modules/@angular-devkit/schematics/tasks/package-manager/executor.js:51:31)

Please provide the environment you discovered this bug in (run ng version)

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 20.0.0
Node: 22.11.0
Package Manager: npm 10.9.0
OS: linux x64

Angular: 20.0.0
... build, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router, ssr

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.2000.0
@angular-devkit/core         20.0.0
@angular-devkit/schematics   20.0.0
@schematics/angular          20.0.0
rxjs                         7.8.2
typescript                   5.8.3
zone.js                      0.15.1

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions