无法从 unpkg 中检索 react-dom.development.js
Unable to retrieve react-dom.development.js from unpkg
我正在学习 ReactJS 并尝试 运行 https://raw.githubusercontent.com/kirupa/kirupa/master/reactjs/helloworld_batman.htm (this is from the instructions at https://www.kirupa.com/react/building_your_first_react_app.htm 处的代码)。
使用 Chrome,"Batman" 永远不会显示,Chrome 开发人员工具记录以下错误:
Access to script at
'https://unpkg.com/react-dom@16.7.0/umd/react-dom.development.js'
(redirected from
'https://unpkg.com/react-dom@16/umd/react-dom.development.js') from
origin 'null' has been blocked by CORS policy: No
'Access-Control-Allow-Origin' header is present on the requested
resource.
果然,当直接请求 react-dom.development.js 时,“网络”选项卡显示缺少 header。
其他注意事项:
- 请求反应时header存在。development.js直接
- https://reactjs.org/docs/cdn-links.html 中的说明显示以这种方式从 unpkg 中检索文件
- IE 11不存在该问题
我做错了什么?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>React! React! React!</title>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<style>
#container {
padding: 50px;
background-color: #EEE;
}
#container h1 {
font-size: 144px;
font-family: sans-serif;
color: #0080a8;
}
</style>
</head>
<body>
<div id="container"></div>
<script type="text/babel">
var destination = document.querySelector("#container");
ReactDOM.render(React.createElement(
"h1",
null,
"Batman"
), destination);
</script>
</body>
</html>
事实证明,如果我取出 "crossorigin" 那么它在 Chrome 中有效!
在 With <script crossorigin='anonymous'>, why is a script "blocked by CORS policy"?
上对此进行了讨论
我正在学习 ReactJS 并尝试 运行 https://raw.githubusercontent.com/kirupa/kirupa/master/reactjs/helloworld_batman.htm (this is from the instructions at https://www.kirupa.com/react/building_your_first_react_app.htm 处的代码)。
使用 Chrome,"Batman" 永远不会显示,Chrome 开发人员工具记录以下错误:
Access to script at 'https://unpkg.com/react-dom@16.7.0/umd/react-dom.development.js' (redirected from 'https://unpkg.com/react-dom@16/umd/react-dom.development.js') from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
果然,当直接请求 react-dom.development.js 时,“网络”选项卡显示缺少 header。
其他注意事项:
- 请求反应时header存在。development.js直接
- https://reactjs.org/docs/cdn-links.html 中的说明显示以这种方式从 unpkg 中检索文件
- IE 11不存在该问题
我做错了什么?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>React! React! React!</title>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<style>
#container {
padding: 50px;
background-color: #EEE;
}
#container h1 {
font-size: 144px;
font-family: sans-serif;
color: #0080a8;
}
</style>
</head>
<body>
<div id="container"></div>
<script type="text/babel">
var destination = document.querySelector("#container");
ReactDOM.render(React.createElement(
"h1",
null,
"Batman"
), destination);
</script>
</body>
</html>
事实证明,如果我取出 "crossorigin" 那么它在 Chrome 中有效!
在 With <script crossorigin='anonymous'>, why is a script "blocked by CORS policy"?
上对此进行了讨论