My current issue involves using dynamic import code to bring in a js library during runtime:
export class AuthService {
constructor() {
import('https://apis.google.com/js/platform.js').then(result => {
console.log(result)
})
}
}
Unfortunately, when attempting to build/serve my Angular project, I encounter the following error message:
external "https://apis.google.com/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 an EcmaScript Module ('output.module: true')?
On top of that, VS Code highlights the import
statement like this:
https://i.stack.imgur.com/KryOP.png
I have attempted adding
"type": "module"
in package.json
and "module": "ESNext"
in tsconfig.json
, however, these changes did not resolve the issue.
Any suggestions on how to rectify this situation?