I'm trying to include hello.js in my angular 5.0.2 project.
Below is the cli version
I have added the script file to the angular-cli.json file.
"scripts": [
"./js/hello.js",
"./js/hello.polyfill.js",
]
The path is correct as i'm also loading style in the angular-cli.json which are loading fine.
In my service file i'm importing hello as below:
declare var hello: any;
declare var gapi: any;
but when i run ng build the console shows the error:
Cannot find module 'hello'.
If i load the files through script tag in the index.html the code and imports works fine .Only when i add it to the angular-cli.json file it stops working.
Please guide Thanks
I'm trying to include hello.js in my angular 5.0.2 project.
Below is the cli version
I have added the script file to the angular-cli.json file.
"scripts": [
"./js/hello.js",
"./js/hello.polyfill.js",
]
The path is correct as i'm also loading style in the angular-cli.json which are loading fine.
In my service file i'm importing hello as below:
declare var hello: any;
declare var gapi: any;
but when i run ng build the console shows the error:
Cannot find module 'hello'.
If i load the files through script tag in the index.html the code and imports works fine .Only when i add it to the angular-cli.json file it stops working.
Please guide Thanks
Share Improve this question asked Nov 24, 2017 at 5:58 Shruti NairShruti Nair 2,0349 gold badges32 silver badges60 bronze badges 3-
1
Why not install the types for hello.js?
npm i -D @types/hellojs
– filoxo Commented Nov 24, 2017 at 6:03 -
2
what is your folder structure? try putting you js file inside
assets/js
folder and provide pathassets/js/hello.js
– ricky Commented Nov 24, 2017 at 6:14 - github./angular/angular-cli/wiki/stories-third-party-lib – R. Richards Commented Nov 24, 2017 at 12:01
1 Answer
Reset to default 3Edit the scripts array in angular-cli.json or angular.json.
You must also specify the assets folder:
"scripts": [
"./assets/js/hello.js",
"./assets/js/hello.polyfill.js",
]