Update :
Thank you all for teaching me to solve the problem. One brilliant guy tell me to use a webserver , but I just want to overcome the specific problem just using a single html file and a single js file. I think the question would be solved because the similar question is solved but I just did it from that step by step , it still didn't work. I am so confused and really appreciate for the specific answer.
I am a fresh man in react. As I want to create a single html file to contain the elements and .js file to contain the class of react, two errors showed:
-
Access to XMLHttpRequest at 'xxxxxx/1.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, edge, https, chrome-untrusted.
-
GET file://xxxxxxx/1.js net::ERR_FAILED
the code I typed is below:
1.html
<div id="app"></div>
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script type="text/babel" src="./1.js"></script>
1.js
import React from "react"
import ReactDOM from "react-dom"
const docItem = document.querySelector('#app')
ReactDOM.render(<p>hello world</p>,docItem)
How to overcome this problem? thank you