Angular10模块加载问题 Dynamic imports are only supported when the ‘--module‘ flag is set to ‘es2020‘, ‘es

1.背景介绍

对一个angular项目进行升级,将angular升级到10,执行启动命令时遇到了模块加载问题

2.问题描述

错误信息

Dynamic imports are only supported when the '--module' flag is set to 
'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
9 loadChildren: () => import('app/user/module').then(m => m.UserModule),

找到了报错信息里的位置,对比一下升级前后变化

升级前

   loadChildren: 'app/user/module#UserModule',

升级后

    loadChildren: () => import('app/user/module').then(m => m.UserModule),

3.解决方案

网上的方案需要修改 tsconfig.json"module": "esnext",
其实主要还是保证 tsconfig.app.json 里的module的值为‘esnext’

tsconfig.app.json

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

tsconfig.json

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

参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值