Error when Importing External Javascript into Angular Typescript

Discussão em 'Angular' iniciado por WIlson PC, Abril 9, 2025.

  1. WIlson PC

    WIlson PC Guest

    I have this bundled JS that i want to import into my TS App The Bundled JS File I tried adding it into index.html under script tag, it worked fine locally I also use 'declare var widget:any' on my ts and worked fine, until i build my app into webpack

    after i build into webpack into /dist folder and deployed into server it returned Unexpected token '<' at widget.js 1:1

    after i opened the js file from console its exactly the same as my index.html file hence the error Unexpected token '<' because index.html start from <!DOCTYPE html

    ive tried importing the JS file straight from my TS with something like

    import * as widget from '/src/xx/xx/widget.js' and importing '/src/xx/xx/widget.js' in vendor.ts file

    but everytime i tried to import JS when building it returned this error Module Parse Failed : unexpected token, you may need an appropriate loader to handle this file type Error when building

    is there any way i can import this JS file into my angular app ? ive tried searching for ways to import JS into the webpack but returned no results

    Continue reading...

Compartilhe esta Página