Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
227 views
in Technique[技术] by (71.8m points)

Using external java-scripts inside reactjs

I am using an external js file inside a helmet tag within my reactjs application

import {Helmet} from "react-helmet";
...
<Helmet>
                <meta charSet="utf-8" />
                <title>My Title</title>
                <link rel="canonical" href="http://example.com/example" />
                <script src="https://unpkg.com/vue" type="text/javascript" />
                  <script src="assets/my-app.js" type="text/javascript" />
            </Helmet>

But the problem that I see in chrome logs, it can not read the js file correctly and gives me

Uncaught SyntaxError: Unexpected token < on

I am not sure where to put the java script external file inside my react app so it is regarded as the java script external file?

EDIT: Based on response below, I am using now localhost:3000/my-app.js, but is there any variable to use instead?

question from:https://stackoverflow.com/questions/65625739/using-external-java-scripts-inside-reactjs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to put it inside of the index.html file in the public folder.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...