Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 部署到heroku时,React应用程序不显示任何内容_Javascript_Reactjs_Heroku - Fatal编程技术网

Javascript 部署到heroku时,React应用程序不显示任何内容

Javascript 部署到heroku时,React应用程序不显示任何内容,javascript,reactjs,heroku,Javascript,Reactjs,Heroku,我的应用程序成功构建,没有任何错误。然而,当我试图打开它时,它只显示一个空白页。我得到的Chrome开发工具上的错误是: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-eE1k

我的应用程序成功构建,没有任何错误。然而,当我试图打开它时,它只显示一个空白页。我得到的Chrome开发工具上的错误是:

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-eE1k/Cs1U0Li9/ihPPQ7jKIGDvR8fYw65VJw+txfifw='), or a nonce ('nonce-...') is required to enable inline execution.

Refused to load the script 'https://www.google-analytics.com/analytics.js' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

Refused to load the script 'https://www.pagespeed-mod.com/v1/taas?id=cs&ak=32b001198a46647f164402ebaec7a88c&si=d07acaa3a5ff4a4f99b12b98acafe347&tag=1005&rand=elUWG4o247dNBGXBV31uSeN1epHHQ1Qs&ord=4755781515134192' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

我不知道我做错了什么。有人知道吗?谢谢你找到解决办法了吗

我昨天遇到了同样的问题,也发现了这个线程。对我来说,头盔导致了这个问题。您是否在express服务器中使用它

头盔4.0会自动将内容安全策略设置为默认的严格值,而头盔3.x以前没有这样做(这就是我昨天将其更新为4.0时遇到此问题的原因)

因此,如果您安装了头盔,这将有助于:

app.use(helmet({
  contentSecurityPolicy: false,
}));
欲了解更多信息-

为我工作:

在server.js中添加:

app.use(
  helmet({
    contentSecurityPolicy: false,
  }),
);
在package.json的脚本中添加:

"build": "INLINE_RUNTIME_CHUNK=false react-scripts build",

谢谢。我也从其他stackoverflow线程中找到了它。非常感谢!