I have this simple react sample using cdn and this are my code. This was all in the same folder.
This is my index.html
<html>
<head>
<script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="news"></div>
<script type="text/babel" src="news.js"></script>
</body>
</html>
This is my News.js
'use strict';
const React = window.React;
const ReactDOM = window.ReactDOM;
const e = React.createElement;
import NewsContent from './NewsContent';
function News(props) {
return (
<div className="container">
<NewsContent />
</div>
);
}
const domContainer = document.querySelector('#news');
const root = ReactDOM.createRoot(domContainer);
root.render(e(News));
My NewsContent.js
'use strict';
const React = window.React;
const e = React.createElement;
function NewsContent(props) {
return (
<div>
<h1>News Content</h1>
<p>Lorem Ipsum</p>
</div>
);
}
export default NewsContent;
My problem is that I tried to import NewsContent component into the news.js it gives me an error said "Uncaught ReferenceError: require is not defined" This is the screenshot of the error. error_image How can I fix this? THank you.
Uncaught ReferenceError: require is not defined
at <anonymous>:6:19
at lve (transformScriptTags.ts:99:10)
at n (transformScriptTags.ts:173:9)
at s (transformScriptTags.ts:204:11)
at t.forEach.e.src.o.onreadystatechange (transformScriptTags.ts:121:9)