Angular 8-延迟加载模块:错误TS1323:仅当'--module'标志为'commonjs'或'esNext'时才支持动态导入 [英] Angular 8 - Lazy loading modules : Error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'
问题描述
当我将Angular从7更新到Angular 8时,由于延迟加载模块而出错
When I updated Angular from 7 to Angular 8, getting error for lazy loading modules
我尝试了角度升级指南中提供的选项
I have tried the options, which are there in the angular upgradation guide
进行以下更改:
之前
loadChildren: '../feature/path/sample-
tage.module#SameTagModule'
之后
loadChildren: () => import('../feature/path/sample-
tags.module').then(m => m.CreateLinksModule)
错误TS1323:仅当'--module'标志为 'commonjs'或'esNext'.
error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.
推荐答案
您正在使用动态导入,因此必须像这样更改tsconfig.json才能将代码定位到esnext
模块
You are using dynamic import so you have to change your tsconfig.json like this to target your code to esnext
module
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "esnext", // add this line
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}
还要确保检查tsconfig.app.json没有类似这样的模块和目标配置
Also make sure to check tsconfig.app.json dont have module and target config something like this
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": []
},
"include": [
"src/**/*.ts"
],
"exclude": [
"src/test.ts",
"src/**/*.spec.ts"
]
}
这篇关于Angular 8-延迟加载模块:错误TS1323:仅当'--module'标志为'commonjs'或'esNext'时才支持动态导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!