React Native報錯無法自動開啟終端

運行React Native項目,終端無法自動打開并報錯。報錯信息如下:

/Users/cloud/Library/Developer/Xcode/DerivedData/FFProject-epfypvlhidieqsbtkbftzahhoglq/Build/Intermediates/FFProject.build/Debug-iphoneos/FFProject.build/Script-40CA3C721C059E3D0007EDF4.sh: line 2: /Users/cloud/Documents/pingan/PA_shunde: is a directory
The file /Users/cloud/Documents/pingan/PA_shunde 2/App_IOS/FFProject/2/App_IOS/react_native/node_modules/react-native/packager/launchPackager.command does not exist.
Can't start packager automatically
/Users/cloud/Library/Developer/Xcode/DerivedData/FFProject-epfypvlhidieqsbtkbftzahhoglq/Build/Intermediates/FFProject.build/Debug-iphoneos/FFProject.build/Script-40CA3C721C059E3D0007EDF4.sh: line 13: /Users/cloud/Documents/pingan/PA_shunde: is a directory
Command /bin/sh failed with exit code 126

意思是在此目錄下沒有launchPackager.command這個文件,但是我自己根據目錄能夠查到這個文件。
后來在工程的Build Phases里面找到了答案。里面有個Run Script選項:

$SRCROOT/../react_native/build.sh $SRCROOT/react-native-build.cfg

if nc -w 5 -z localhost 8081 ; then
if ! curl -s "http://localhost:8081/status" | grep -q "packager-status:running" ; then
echo "Port 8081 already in use, packager is either not running or not running correctly"
exit 2
fi
else
open $SRCROOT/../react_native/node_modules/react-native/packager/launchPackager.command || echo "Can't start packager automatically"
fi

$SRCROOT/../react_native/react-native-xcode.sh $SRCROOT/../react_native/

由此可以看出是這個腳本沒有運行從而報錯“Can't start packager automatically”
只需將下面Run script only when installing打鉤即可。


原本以為這樣修改之后就沒有問題了,但是發現這樣修改雖然build成功了,但是運行起來會報紅屏。“未能完成操作,loadJSBundle is nil”;

所以上面打鉤只能build成功,并不能解決根本問題,后來google之后在Facebook官網上找到了答案。是我的目錄名稱里面含有空格導致的。我的工程命名為PA_shunde 2文件夾。

I discovered the problem. One of the directories that the project folder was in had a space in its name. As soon as I removed the space, hitting command + R automatically ran the npm server!

最后將含有空格的文件夾名稱改為不含空格即可完美運行。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容