Thursday 31 December 2020

Using ES6 Module Libraries in Angular Applications and Unexpected token 'export' Error

I have a JavaScript library I'm trying use within an Angular application. It is written with ES6 syntax and exports itself as a module.

export { Q as Library };

Imported into Angular.json as you do:

architect: {
build: {
options: {
   "scripts": [
      "src/assets/libs/library.min.js"
   ]

Angular loads the script but with a module syntax error.

scripts.js:1 Uncaught SyntaxError: Unexpected token 'export'

Here is my tsconfig

compilerOptions
  "target": "es2020",
  "module": "es2020",
  "lib": [
      "es2020",
      "dom"
  ]

How can I properly import this module into the application?



from Using ES6 Module Libraries in Angular Applications and Unexpected token 'export' Error

No comments:

Post a Comment