xcode using wrong node.js version

前端 未结 6 496
闹比i
闹比i 2020-12-30 00:25

I am new to React Native. I used react-native init XXX to create a new project. When launch the xcodeproj, I got an error saying:

  const setupE         


        
相关标签:
6条回答
  • 2020-12-30 01:08

    For me, adding this to /etc/profile or to ~/.profile worked:

    export NVM_DIR="$HOME/.nvm"
    [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"  
    

    The reason this is necessary is because XCode uses /bin/sh by default and it loads the profiles from the files I specified.

    Note: altering /etc/profile requires you to use sudo. Not sure if this is even possible on MacOS X 10.15 Catalina since I believe they made the system directories to be read-only, no matter what. But if you are able to set it here, this will make it work for any user who has nvm installed.

    0 讨论(0)
  • 2020-12-30 01:14

    The problem seems to occur when you have installed react-native-cli with the wrong Node (and thus npm) version.

    First shut down xcode and let's make sure that there is no old node processes running, I'm not sure if this is necessary but it is good to make sure:

    $ ps -e|grep node
    $ kill {process number(s) here}
    

    Then set the default nvm node version to the one you want to use, for example:

    $ nvm alias default 6.6.0
    

    Then restart your terminal and make sure that the node version is now the one you want by default:

    $ node -v
    v6.6.0
    

    Now reinstall react-native-cli with the new node version active (it affects the npm version):

    $ npm install -g react-native-cli
    

    Now running $ react-native run-ios should run xcode with the proper version! (If it doesn't, make sure to restart your terminal/xcode and try again).

    0 讨论(0)
  • 2020-12-30 01:15

    I resolved the issue by adding . ~\.bash_profile to the top of shell script.

    0 讨论(0)
  • 2020-12-30 01:16

    Seeing as this is the top result in Google while searching for this error, the following is the only thing that worked for me.

    I had to uninstall node (that was previously installed with the pkg from the Node website), uninstall nvm and reinstall node with Brew.

    Link for more information.

    0 讨论(0)
  • 2020-12-30 01:20

    I resolved by adding . ~/.nvm/nvm.sh to the top of the shell script in Build Phases

    0 讨论(0)
  • 2020-12-30 01:25

    Add your node path to Build Phases / Bundle React Native Code and images settings

    Setting

    0 讨论(0)
提交回复
热议问题