External script for type="text/babel" not working

Viewed 1173

Why external script for type="text/babel" not working in ReactJS ? I put the index.html and foo.js in the same folder. Nothing show after I open the index.html file with Google Chrome


index.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8"/>
        <title>ReactJS</title>
        <script src="https://unpkg.com/react@17/umd/react.development.js"></script>
        <script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
        <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
        <script type="text/babel" src="foo.js"></script>
    </head>
    <body>

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

foo.js

ReactDOM.render(
  <h1>Hello World</h1>,
  document.getElementById('root')
);
1 Answers

Just include the babel file before the main. It will work as expected.

<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script type="text/babel" src="./main.js"></script>
Related