2

I have a problem with adding a script to Angular 2 with ng cli outside of the node_modules folder. The script doesn't exist ( or at least I didn't find it ) in the npm registries and it's just a single file I wish to load but cannot:

This is in angular-cli.json :

"scripts": [
    "assets/one-signal-sdk.js"
],

This throws a syntax error, saying:

"Unexpected token ? in JSON at position 0"

But, if I manually add the package to node_modules and load it like this:

"scripts": [
    "../node_modules/one-signal/one-signal-sdk.js"
],

It's working perfectly fine. Of course, I cannot just add it manually and leave it there because no one will be able to download it via npm install.

Is there a way to add a custom script to the build? Thanks.

1 Answer 1

2

This should work fine

"scripts": [
    "assets/one-signal-sdk.js"
],

Try to put in this file something simple like document.write("test");. If that works, the problem is specific to the content of one-signal-sdk.js.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, you're right, it seems the problem is indeed in the script I'm adding to the page. That's strange because it's working fine when added from node_modules :( EDIT: I fixed my problem my adding the script tag to the html: <script type="text/javascript" src="assets/one-signal-sdk.js"></script> Adding it like this doesn't throw an error in the build process. Thanks for your response :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.