4

i have created a application using create-react-app now i need to include some of the script which i have like bootstap.min.js , jquery.min.js ,script.js , i have placed these files inside app/styles/js ans referencing them in index.html using script tag but if i do so i am getting Uncaught SyntaxError: Unexpected token < error in the console.

i have tried these solutions ,

ReactJS: "Uncaught SyntaxError: Unexpected token <",

if i reference using CDN it works fine but script.js is the custom create hense CDN is not available

<body>

<noscript>You need to enable JavaScript to run this app.</noscript>

<div id="root"></div>


   <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script> 
    <script src="../src/Styles/js/script.js"></script> //error here    
</body>
4
  • keep your script.js in public directory and update the path. you can't use path for scripts from src. Commented Jun 13, 2019 at 6:09
  • have tried it doing so will not give error in the console but functionality of the script is not getting applied. Commented Jun 13, 2019 at 6:25
  • check in network tab, if it is loading or not? Commented Jun 13, 2019 at 6:43
  • it is not getting loaded ..network tab is empty Commented Jun 13, 2019 at 9:44

1 Answer 1

8

Create a js folder into public folder and put all your js file's into that js folder. And you can include that js file like,

<script src="%PUBLIC_URL%/js/script.js"></script>
Sign up to request clarification or add additional context in comments.

4 Comments

did it but the it is not getting loaded . Nothing is showing up in network tab.
@ashish check in the source tab also. Also check your script file for any syntax error.
in the soure it is present and there is no error in the script .
so it means your js file is loading fine. check console for any error. check what functionality you wrote in that file is being executed. What error comes after executing that functions.

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.