gpt4 book ai didi

javascript - Angular 8 - 延迟加载模块 : Error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'

转载 作者:IT王子 更新时间:2023-10-29 03:10:14 27 4
gpt4 key购买 nike

当我将 Angular 从 7 更新到 Angular 8 时,出现延迟加载模块的错误

我已经尝试了 Angular 升级指南中的选项

进行了以下更改:

之前

    loadChildren: '../feature/path/sample- 
tage.module#SameTagModule'

之后

   loadChildren: () => import('../feature/path/sample- 
tags.module').then(m => m.CreateLinksModule)

error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'.

最佳答案

您正在使用动态导入,因此您必须像这样更改您的 tsconfig.json 以将您的代码定位到 esnext 模块

{
"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 没有像这样的模块和目标配置

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

关于javascript - Angular 8 - 延迟加载模块 : Error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56375703/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com