3

After updating my app to angular 8 my routes did not change to new syntax loadChildren: () => import('./listing/listing.module').then(m => m.ListingModule) so i did this manually but i am getting Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'. error.

After reading some answers i found to change "module": "esnext" in tsconfig.json file. But even after this change my error is still there.

Below is my code:

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "esnext",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  }
}

tsconfig.app.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

Can please anyone tell what is wrong in the code?

Gaurav Aggarwal
  • 9,809
  • 6
  • 36
  • 74
  • From which version you're upgrading to 8? Some days ago we did it from 6 to 8, Didn't get such error. – Prawin soni Sep 30 '19 at 12:01
  • Possible duplicate of [Angular 8 - Lazy loading modules : Error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'](https://stackoverflow.com/questions/56375703/angular-8-lazy-loading-modules-error-ts1323-dynamic-import-is-only-supporte) – Farhat Zaman Sep 30 '19 at 12:31
  • @FarhatZaman no it is not. In the question marked by you the OP was asking how to remove dynamic lazy load error and in my question i did the changes suggested in the answers but still error is there. – Gaurav Aggarwal Oct 01 '19 at 10:17
  • Mind you share your code on github ? – Tony Ngo Oct 01 '19 at 10:20
  • 1
    @GauravAggarwal I face the same issue and follow the answer but still, the error was there. then I restart and invalidate the cache of my IntelliJ idea and error was gone. – Farhat Zaman Oct 01 '19 at 10:32

2 Answers2

0

This might help, my tsconfig.app.json looks like this:

{
 "extends": "../tsconfig.json",
 "compilerOptions": {
  "outDir": "../out-tsc/app",
  "baseUrl": "./",
  "types": []
 },
 "exclude": [
  "test.ts",
  "**/*.spec.ts"
 ]
}
Prawin soni
  • 423
  • 2
  • 8
0

First try to restart your angular cli server also

If that is not the case add this in your tsconfig.app.json also

"module": "esnext"
Tony Ngo
  • 19,166
  • 4
  • 38
  • 60