守著星空守著你
2021-11-18 16:22:17
我react-create-app用來構(gòu)建我的 chrome 擴(kuò)展。當(dāng)我npm run build在 react-create-app 中使用時出現(xiàn)錯誤:拒絕執(zhí)行內(nèi)聯(lián)腳本,因為它違反了以下內(nèi)容安全策略指令:“script-src 'self'”。啟用內(nèi)聯(lián)執(zhí)行需要“unsafe-inline”關(guān)鍵字、哈希(“sha256-5=')或隨機(jī)數(shù)(“nonce-...”)。錯誤 index.html<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="theme-color" content="#000000" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" /> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous" /> <!-- manifest.json provides metadata used when your web app is installed on a user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ --> <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> <!-- Notice the use of %PUBLIC_URL% in the tags above. It will be replaced with the URL of the `public` folder during the build. Only files inside the `public` folder can be referenced from the HTML. Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> <title>React App</title> </head> <body> <noscript>You need to enable JavaScript to run this app.</noscript> <div id="root"></div>
3 回答

慕妹3242003
TA貢獻(xiàn)1824條經(jīng)驗 獲得超6個贊
經(jīng)過幾個小時的沮喪之后,我找到了一個可行的解決方案。Mac 和 PC 之間在運行腳本方面存在差異。我發(fā)現(xiàn)的很多答案都帶有“集合”和“不帶”。有“&&”和沒有......沒有一個為我工作。
TLDR:使用“cross-env” npm 包,如下所示:
cross-env INLINE_RUNTIME_CHUNK=false react-scripts build
這適用于 PC,也可能適用于 Mac。當(dāng)然,你需要npm install --save-dev cross-env
之前。

翻過高山走不出你
TA貢獻(xiàn)1875條經(jīng)驗 獲得超3個贊
在 中package.json
,將"build"
腳本更新為:
"build": "INLINE_RUNTIME_CHUNK=false react-scripts build"

慕絲7291255
TA貢獻(xiàn)1859條經(jīng)驗 獲得超6個贊
對于那些仍然有問題的INLINE_RUNTIME_CHUNK not recognized as a command
,您需要將set添加到構(gòu)建腳本中。
"build": "set INLINE_RUNTIME_CHUNK=false&&react-scripts build"
這樣INLINE_RUNTIME_CHUNK值將在構(gòu)建時設(shè)置,而不是在環(huán)境變量中查找。
添加回答
舉報
0/150
提交
取消