javascript - (Angular 12)目标环境不支持动态 import() 语法,因此无法在脚本中使用外部类型“模块”
问题描述
我有以下动态导入代码在运行时导入 js 库:
export class AuthService {
constructor() {
import('https://apis.google.com/js/platform.js').then(result => {
console.log(result)
})
}
}
但是,当我尝试构建/服务 Angular 项目时,我得到:
external "https://apis.google.com/js/platform.js" - 错误:目标环境不支持动态 import() 语法,因此无法在脚本中使用外部类型“模块”您是说构建一个 EcmaScript 模块 ('output.module: true')?
我尝试添加"type": "module"
inpackage.json
和"module": "ESNext"
in tsconfig.json
,但没有运气。
我怎样才能解决这个问题?
解决方案
Dynamic imports only works since ES2020. Please, check your tsconfig.json in order to know what version is your target.
推荐阅读
- html - 日期时间输入字段最小值和最大值的角度绑定
- angular - Angular 7具有不同参数的相同路由
- angular - 在 Nginx 上服务两个 SPA 应用程序
- javascript - v-for Vuejs中使用AXIOS时如何调用方法
- python - pip3 install ruamel.yaml[jinja2] 破坏了 ruamel.yaml
- android - 设置自定义属性android的值
- database - 可以指定在集群中保存哪个 mongoDB 实例数据?
- haskell - 是否有从单例中提取值的函数?
- python-3.x - 如何使用机器学习算法训练和测试数据以进行分类
- ios - Appium1.13.0 似乎不支持 XCUITest 模拟器架构