運行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
意思是在此目錄下沒有l(wèi)aunchPackager.command這個文件咖熟,但是我自己根據(jù)目錄能夠查到這個文件嘲玫。
后來在工程的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打鉤即可除破。
原本以為這樣修改之后就沒有問題了牧氮,但是發(fā)現(xiàn)這樣修改雖然build成功了,但是運行起來會報紅屏瑰枫□飧穑“未能完成操作,loadJSBundle is nil”;
所以上面打鉤只能build成功光坝,并不能解決根本問題剖毯,后來google之后在Facebook官網(wǎng)上找到了答案。是我的目錄名稱里面含有空格導致的教馆。我的工程命名為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!