admin管理员组文章数量:1436135
I have the following dynamic import code to import a js library at runtime:
export class AuthService {
constructor() {
import('.js').then(result => {
console.log(result)
})
}
}
However when I try to build/serve the Angular project I get:
external ".js" - Error: The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script Did you mean to build a EcmaScript Module ('output.module: true')?
In addition, vs-code highlights the import
with the following:
I tried adding "type": "module"
in package.json
and "module": "ESNext"
in tsconfig.json
, but with no luck.
How can I fix this?
I have the following dynamic import code to import a js library at runtime:
export class AuthService {
constructor() {
import('https://apis.google./js/platform.js').then(result => {
console.log(result)
})
}
}
However when I try to build/serve the Angular project I get:
external "https://apis.google./js/platform.js" - Error: The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script Did you mean to build a EcmaScript Module ('output.module: true')?
In addition, vs-code highlights the import
with the following:
I tried adding "type": "module"
in package.json
and "module": "ESNext"
in tsconfig.json
, but with no luck.
How can I fix this?
Share Improve this question asked Jul 6, 2021 at 16:38 Two HorsesTwo Horses 1,7123 gold badges19 silver badges43 bronze badges 01 Answer
Reset to default 2Dynamic imports only works since ES2020. Please, check your tsconfig.json in order to know what version is your target.
本文标签:
版权声明:本文标题:javascript - (Angular 12) The target environment doesn't support dynamic import() syntax so it's not possible to 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745337202a2654096.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论