【发布时间】:2019-06-30 07:58:56
【问题描述】:
我的服务器突然空白,我在浏览器控制台中收到以下错误消息:
Uncaught TypeError: Cannot read property 'current' of undefined react-dom.production.min.js:134 at Vg...
可能是什么问题? React CDN 服务器有问题?
我在 html 中的脚本是:
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
在开发模式下,消息是(来自我的开发环境):
(索引):1 访问来自原点“http://localhost”的“https://unpkg.com/react-dom@16.7.0/umd/react-dom.development.js”处的脚本(重定向自“https://unpkg.com/react-dom@16/umd/react-dom.development.js”)已被 CORS 策略阻止:否“访问控制允许源”请求的资源上存在标头。 unpkg.com/react-dom@16.7.0/umd/react-dom.development.js:1 加载资源失败:net::ERR_FAILED App.js:63 Uncaught ReferenceError: ReactDOM is not defined 在 App.js:63
我的 react 组件是从 jsx 翻译成带有 Babel 网页的 js。预设:es2015, stage-2
我通过从脚本中删除“crossorigin”来启动主应用程序。但它只能在开发模式下工作,不能在生产模式下工作。服务器启动但速度很慢。它显示了
[Violation] 'react-invokeguardedcallback' 处理程序耗时 262 毫秒 react-dom.development.js:128
生产模式的标题
Request URL: https://unpkg.com/react-dom@16.8.0/umd/react-dom.production.min.js
Request Method: GET
Status Code: 200
Remote Address: 104.16.126.175:443
Referrer Policy: no-referrer-when-downgrade
access-control-allow-origin: *
cache-control: public, max-age=31536000
cf-cache-status: HIT
cf-ray: 4a4e1438e86e5af7-HEL
content-encoding: br
content-type: application/javascript; charset=utf-8
date: Wed, 06 Feb 2019 13:49:15 GMT
etag: W/"1a24b-tnTtN6dcAkNhpzBK8ZBEsa24AAw"
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
last-modified: Sat, 26 Oct 1985 08:15:00 GMT
server: cloudflare
status: 200
strict-transport-security: max-age=31536000; includeSubDomains; preload
vary: Accept-Encoding
x-cloud-trace-context: 7ef73148e43be758d63b9525cae9fe1c
x-content-type-options: nosniff
:authority: unpkg.com
:method: GET
:path: /react-dom@16.8.0/umd/react-dom.production.min.js
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: fi-FI,fi;q=0.9,en-US;q=0.8,en;q=0.7
origin: https://www.suomiverkko.online
referer: https://www.suomiverkko.online/
user-agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 OPR/57.0.3098.106
【问题讨论】:
-
react cdn 没问题,你的 react 代码有问题。在代码中的某处,您试图读取某个对象的属性
current,但该对象未定义。您可以查看开发模式下的错误回溯,以确定错误发生的确切位置。 -
它已经工作了 1 年了。为什么现在出现这个错误?
-
我猜你是从某个 api 获取你的 react 应用程序中的数据。可能在获取数据时出现问题,或者它没有发送您的反应应用程序期望的数据。尝试刷新页面,错误不断发生,尝试在开发模式下访问该页面以查看详细错误。如果您已经处于开发模式,您应该在控制台中有详细的错误回溯。将整个内容复制粘贴到您的问题中。如果这个错误只是一次性的,而现在您的网站运行良好,您就可以不用再担心了。
-
Something to do header Access-Control-Allow-Origin..(添加到问题中)。似乎没有一次,服务器似乎仍然空白
-
非常感谢 Vaibhav 的帮助。
标签: javascript reactjs server cdn