DEV Community

rss81
rss81

Posted on

unable to load external js file

Why does the first example work when the jsx script is inline but the second example not work:

<!DOCTYPE html>
<html>
<head>
<title>ReactJS Example</title>
<script src='react/react.js'></script>
<script src='react/react-dom.js'></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
<div id='container'>
</div>
<script type='text.jsx'>
ReactDOM.render(
<h1> Hello, React! </h1>,
document.getElementById('container')
);
</script>
</body>
</html>

second example:

<!DOCTYPE html>
<html>
<head>
<title>ReactJS Example</title>
<script src='react/react.js'></script>
<script src='react/react-dom.js'></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
<div id='container'>
</div>
<script src='hello.js' type='text.jsx'></script>
</body>
</html>

hello.js:

ReactDOM.render(
<h1> Hello, React! </h1>,
document.getElementById('container')
);

Top comments (4)

Collapse
 
tobiassn profile image
Tobias SN

You misspelled the name of the script. You probably want hello.js instead of hello’js.

Please, check your logs next time.

Collapse
 
rss81 profile image
rss81

sorry about that, just a typo. When fixed file still does not load

Collapse
 
tobiassn profile image
Tobias SN

What do the logs say?

Collapse
 
rss81 profile image
rss81

also tried type='text/babel'