ionic-cli: Livereload fails with error require() of ES modules is not supported

Steps to Reproduce:

  • Create New Ionic 6 Hello World App (Cordova)
  • Update to Angular 13 deps.
  • Run ionic cordova run android --livereload

Description: When running with LIVERELOAD arg, gets this error immediately.

ng.cmd run app:ionic-cordova-serve --host=localhost --port=8100 --platform=android --consolelogs --consolelogs-port=53703 [ng] An unhandled exception occurred: Must use import to load ES Module: D:.…\node_modules@angular\compiler-cli\bundles\index.js [ng] require() of ES modules is not supported. [ng] require() of D:.…\node_modules@angular\compiler-cli\bundles\index.js from D:.…\node_modules@ionic\angular-toolkit\node_modules@angular-devkit\build-angular\src\webpack\configs\common.js is an ES module file as it is a .js file whose nearest parent package.json contains “type”: “module” which defines all .js files in that package scope as ES modules. [ng] Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove “type”: “module” from D:.…\node_modules@angular\compiler-cli\package.json.

My ionic info:

Ionic:

   Ionic CLI                     : 6.18.1 (C:\Users\steve\AppData\Roaming\npm\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 6.0.1
   @angular-devkit/build-angular : 13.1.2
   @angular-devkit/schematics    : 13.1.2
   @angular/cli                  : 13.1.2
   @ionic/angular-toolkit        : 5.0.3

Cordova:

   Cordova CLI       : 11.0.0
   Cordova Platforms : android 10.1.1, browser 6.0.0, ios 6.2.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, cordova-plugin-ionic 5.5.1, (and 12 other plugins)

Utility:

   cordova-res : 0.15.4
   native-run  : 1.5.0

System:

   Android SDK Tools : 26.1.1 (C:\Users\steve\AppData\Local\Android\Sdk)
   NodeJS            : v14.18.0 (C:\Program Files\nodejs\node.exe)
   npm               : 6.14.15
   OS                : Windows 10

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 6
  • Comments: 15

Most upvoted comments

I confirm it works on angular 13 with ionic/angular-toolkit downgrade to 4 version. Run npm i @ionic/angular-toolkit@4.0.0

Also you need to run npm i @angular-devkit/architect if you get node errors like this: An unhandled exception occurred: Cannot find module '@angular-devkit/architect'

This is temporarily workaround till ionic team fix ionic/angular-toolkit 5+ lib version. 😇

when downgrading @ionic/angular-toolkit to 4.0.0 it works with me

npm install @ionic/angular-toolkit@4.0.0

The final solution for cordova project is mentioned here Updates to Ionic Angular Toolkit

You have to install cordova-builders

npm i @ionic/cordova-builders

then edit the file angular.json

replace all @ionic/angular-toolkit with @ionic/cordova-builders

I am facing the same problem 😢 . It worked with: npm install @ionic/angular-toolkit@4.0.0

Same problem.

` Ionic:

Ionic CLI : 6.18.1 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 6.0.1 @angular-devkit/build-angular : 13.1.2 @angular-devkit/schematics : 13.1.2 @angular/cli : 13.1.2 @ionic/angular-toolkit : 5.0.3

Cordova:

Cordova CLI : 10.0.0 Cordova Platforms : android 10.1.0, ios 6.2.0 Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 17 other plugins)

Utility:

cordova-res : 0.15.4 native-run : 1.5.0

System:

Android SDK Tools : 26.1.1 (/Users/vs/Library/Android/sdk) ios-deploy : 1.11.4 ios-sim : 8.0.2 NodeJS : v14.18.1 (/usr/local/bin/node) npm : 6.14.15 OS : macOS Big Sur Xcode : Xcode 13.2.1 Build version 13C100 `

I support, the same problem. When can I wait for a fix? This greatly complicates the development!

it work with me with angular 13

Ionic team, please comment this issue…