Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
How to import js file in react using online CDN

Please I am trying to run react app using external CDN, and having issues on the html file saying:

Uncaught ReferenceError: require is not defined index.html:3 This is the html code:

    <!DOCTYPE html>
<html>
  <head>
    <meta charset='UTF-8'>
    <link rel="stylesheet" href="styles/style.css">
    <script src='https://unpkg.com/react@16.3.1/umd/react.production.min.js'></script>
    <script src='https://unpkg.com/react-dom@16.3.1/umd/react-dom.production.min.js'></script>
    <script src='https://unpkg.com/react-router-dom@5.0.0/umd/react-router-dom.min.js'></script>
    <script src='https://unpkg.com/babel-standalone@6.26.0/babel.js'></script>
  </head>
  <body>
    <div id='root'></div>
    <script type='text/babel'>
      import Todo from 'component/Todo.js';
      const App = () =>(
    <div>
      <h1>My Todos</h1>
      <Todo />
    </div>
      )
    ReactDOM.render(<App />, document.querySelector('#root'));
    </script>
  </body>
</html>

And this the JavaScript code

    function Todo (){
  return (<div className="card">
        <h2>TITLE</h2>
        <div className="actions">
          <button className="btn">Delete</button>
        </div>
      </div>);
}
export default Todo;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can import external scripts from another server like this :

componentDidMount() {
  const script = document.createElement("script");
  script.src = "/static/libs/your_script.js";
  script.async = true;
  script.onload = () => this.scriptLoaded();

  document.body.appendChild(script);
}

Then to make sure your file is loaded :

 scriptLoaded() {
   // your stuff to do!
 }

Another way is using react Helmet:

first install it using :

npm install --save react-helmet

then use it like this

  <Helmet>
    <script src="www.test.ts" />

  </Helmet>

note that in this way your script will load in the <head>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!