question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

including external javascript libraries in new react app which is configured using create-react-app

See original GitHub issue

This issue is a:

  • Question / support request

hello all!! I am new to react.js . Actually i downloaded a theme which have external javascript libraries i.e bootstrap.min.js , jquery.min.js, slider.js , jquery-flexslider,min.js . I created a react app using create-react-app and i copied all the external javascript libraries and css files in index.html of the public folder of my react app and copied all the html of index.html of my theme in app.js which i downloaded. All the css are working fine but the javascript libraries are not working on the page. Following is the demo of how i included the css files and javascript libraries in index.html of the public folder.

<script src="/assets/javascript/jquery.min.js"></script>
<script src="/assets/javascript/bootstrap.min.js"></script> 
<script src="/assets/javascript/jquery.easing.js"></script>    
<script src="/assets/javascript/jquery-waypoints.js"></script>
<link rel="stylesheet" type="text/css" href="/assets/stylesheets/bootstrap.css" > <link rel="stylesheet" type="text/css" href="/assets/stylesheets/style.css"> <link rel="stylesheet" type="text/css" href="/assets/stylesheets/responsive.css">

Now my question is, how should i include the javascript libraries so that it start working for me. This might be a silly question, but i am new to it. Pardon me. I am trying for it from 2 days and did a lot of search for it but i failed. Please help me out with this issue. I tried to put all the files in the src folder of my react app but it still not working.

Thanks in advance

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:24
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

87reactions
kunwang0916commented, Jan 16, 2018

@malishahi Try following steps:

  • including the external js file link in your /public/index.html
  • use the external library with prefix window.

for example, JQuery.

  • put following line in your /public/index.html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  • use it in your project:
window.$("#btn1").click(function(){
    alert("Text: " + $("#test").text());
});
4reactions
valorloffcommented, Oct 2, 2017

need help! in Create React App don’t works external libs like flexslider.min.js, parallax.js, massonry etc, folder structure (course with "%PUBLIC_URL% replaced):

<script src="/__/firebase/4.3.0/firebase-app.js"></script>
    <script src="/__/firebase/4.3.0/firebase-database.js"></script>
    <script src="/__/firebase/init.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <script src="/assets/theme/js/flickr.js"></script>
    <script src="/assets/theme/js/flexslider.min.js"></script>
    <script src="/assets/theme/js/lightbox.min.js"></script>
    <script src="/assets/theme/js/ytplayer.min.js"></script>
    <script src="/assets/theme/js/countdown.min.js"></script>
    <script src="/assets/theme/js/smooth-scroll.min.js"></script>
    <script src="/assets/theme/js/parallax.js"></script>

folder structure as I understand, this is due to the loading order of lib’s files in your doc:

Note that we normally encourage you to import assets in JavaScript files instead

could you show example how to, where locate and use imports of external .js?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Including external JavaScript libraries in new react app which ...
I am new to react.js. I downloaded a theme which have external JavaScript libraries i.e bootstrap.min.js , jquery.min.js, slider.js, jquery- ...
Read more >
Including external JavaScript libraries in new react app which ...
Coding example for the question Including external JavaScript libraries in new react app which is configured using create-react-app-Reactjs.
Read more >
How To Set Up a React Project with Create React App
In this step, you'll create a new application using the npm package manager to run a remote script. The script will copy the...
Read more >
Create a New React App
If you're learning React or creating a new single-page app, use Create React App. If you're building a server-rendered website with Node.js, try...
Read more >
How to include an external JavaScript library to ReactJS
Creating React Application : · Project Structure: · Approach 1: Using react-script-tag Package · Installation: · Import 'ScriptTag' component: · Call ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found