在Electron 中使用react+ webpack创建项目 运行时报错 ‘unsafe-eval’ is not an allowed
问题
在Electron 中使用react+ webpack创建项目,运行Electron后,控制台报错: Uncaught EvalError: Refused to evaluate a string as JavaScript because ‘unsafe-eval’ is not an allowed source of script in the following Content Security Policy directive: “script-src ‘self’”.
解决
Electron中开启了内容安全策略(CSP) default-src 'self'; script-src 'self' ,将meta标签的Content-Security-Policy中的content改为 default-src 'self' 'unsafe-eval'; script-src 'self' 'unsafe-eval' 重新打包运行就好了
html 代码
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self' 'unsafe-eval'; script-src 'self' 'unsafe-eval'"
/>
<meta
http-equiv="X-Content-Security-Policy"
content="default-src 'self' 'unsafe-eval'; script-src 'self' 'unsafe-eval'"
/>
|