close

我們都知道,React Native 在執行的時候
都會生成一個 bundle 文件來載入 js 的 code
例如以 Andorid 來說就是 index.andoird.bundle
這個文件通常都是我們執行 $react-native start 與伺服器連線之後
再輸入下列指令 
curl -k "http://localhost:8081/index.android.bundle" > ./app/src/main/assets/index.android.bundle
在伺服器端生成 bundle 存入 assets 資料夾

 

不過也有本地生成的方式
就不用事先連線到 React Native 的服務器了
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output ./app/src/main/assets/index.android.bundle --assets-dest ./app/src/main/res/

 

一般來說,當我們的 React Native 專案要上架時
都需要有一個打包 apk 的動作
而 apk 就需要包含這個 bundle 文件
不過我這次在本地生成的時候遇上了一個問題
訊息如下:

child_process.js:614

    throw err;

    ^

Error: spawnSync /Users/80005455/Desktop/ResourceCode/SFA3_2.0_RN_Willy/node_modules/react-native/local-cli/setup_env.sh EACCES

    at exports._errnoException (util.js:1024:11)

    at spawnSync (child_process.js:569:20)

    at Object.execFileSync (child_process.js:606:13)

    at Object.run (/Users/80005455/Desktop/ResourceCode/SFA3_2.0_RN_Willy/node_modules/react-native/local-cli/cliEntry.js:136:16)

    at Object.<anonymous> (/usr/local/lib/node_modules/react-native-cli/index.js:117:7)

    at Module._compile (module.js:569:30)

    at Object.Module._extensions..js (module.js:580:10)

    at Module.load (module.js:503:32)

    at tryModuleLoad (module.js:466:12)

    at Function.Module._load (module.js:458:3)

 

一開始我也不知道是哪裡出了問題
後來 GOOGLE 之後,看到有人有類似的問題
我就跟著試了一下
我們這次的情況是權限問題
生成 bundle 時,要訪問 setup_env.sh 時遭到拒絕
即然知道原因那就簡單了
輸入指令 chomd -R 777 node_modules/ 把權限打開就行囉。





資料來源:
https://github.com/facebook/react-native/issues/10205



 


arrow
arrow
    全站熱搜

    顏澤偉 發表在 痞客邦 留言(0) 人氣()