— 安裝 —
1.安裝react-devtools時(shí)報(bào)錯(cuò):
Error: EACCES: permission denied, mkdtemp '/usr/local/lib/node_modules/react-devtools/node_modules/electron/electron-download-VcLLBk'
npm WARN ws@7.4.4 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.4.4 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! electron@9.4.4 postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the electron@9.4.4 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/rong/.npm/_logs/2021-03-24T02_33_58_372Z-debug.log
解決方法:
sudo npm install -g react-devtools --unsafe-perm=true
解釋:
官方文檔 https://docs.npmjs.com/misc/c...
就是說 npm 出于安全考慮不支持以 root 用戶運(yùn)行,即使你用 root 用戶身份運(yùn)行了本股,npm 會(huì)自動(dòng)轉(zhuǎn)成一個(gè)叫 nobody 的用戶來運(yùn)行童本,而這個(gè)用戶幾乎沒有任何權(quán)限这吻。這樣的話如果你腳本里有一些需要權(quán)限的操作藻懒,比如寫文件(尤其是寫 /root/.node-gyp)却邓,就會(huì)崩掉了。
為了避免這種情況峦嗤,要么按照 npm 的規(guī)矩來蕊唐,專門建一個(gè)用于運(yùn)行 npm 的高權(quán)限用戶;要么加 --unsafe-perm 參數(shù)烁设,這樣就不會(huì)切換到 nobody 上替梨,運(yùn)行時(shí)是哪個(gè)用戶就是哪個(gè)用戶,即使是 root装黑。
</article>
— 二 — 報(bào)錯(cuò)
Unable to load script.Make sure you're either running a metro server or that
解決方法:
1.創(chuàng)建android/app/src/main/assets文件夾
2.執(zhí)行命令
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
(可能出現(xiàn)以下報(bào)錯(cuò))
index.android.js` was not found
原因以及解決方法:
是react native更新的一些變動(dòng)副瀑。原來工程中會(huì)創(chuàng)建:index.ios.js 和index.android.js,現(xiàn)在只會(huì)創(chuàng)建index.js恋谭。一個(gè)簡(jiǎn)單的規(guī)避方法俗扇,就是copy 一份index.js 文件命名為index.android.js即可