[英]two problems on implementing react without create-react-app?
I am creating a simple react app to practice creating stuffs without dependencies provided by create-react-app (webpack - babel ....) 我正在创建一个简单的react应用程序,以练习创建没有create-react-app提供的依赖项的东西(webpack-babel ....)
I am faced with two problems 我面临两个问题
this is the code: 这是代码:
HTML 的HTML
<html>
<head><head>
<body>
<div id="App"> </div>
<script type="module" src="script.js" ></script>
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
</body>
</html>
JS JS
window.onload = () => {
class App extends React.Component {
render() {
return(
<div className="App">
<p>any paragraph</p>
</div>
)
}
}
ReactDom.render(App, document.getElementById('App'))
}
The first problem is: 第一个问题是:
Nothing is happening when adding the type
attribute to the script
tag and set its value to "module"
, nothing works at all, as if js engine could not access the script!! 将type
属性添加到script
标签并将其值设置为"module"
,什么也没有发生,根本没有任何效果,好像js引擎无法访问该脚本!
The second problem: 第二个问题:
After removing type="module"
, it works but with a console error Uncaught SyntaxError: Unexpected token <
删除type="module"
,它可以工作,但出现控制台错误Uncaught SyntaxError: Unexpected token <
So why these two problems happens and how to solve them?? 那么为什么会发生这两个问题以及如何解决呢?
Try loading script.js
last. 尝试最后加载script.js
。 That is, after react-dom
is loaded. 即加载了react-dom
之后。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.