简体   繁体   中英

React Native packager.sh: line 11: node: command not found

I initiated a new project with Create-React-Native-App and then ejected from the project. I followed the instructions for the React-Native docs I opened up a virtual device on Android Studio and ran yarn android to build the app. I then get this error message:

在此输入图像描述

I'm currently using Node 8.11.1 and the command is working normally on my terminal. I installed it with NVM.

In the packager.sh file, this is what line 11 is:

node "./local-cli/cli.js" start "$@"

Here are my .bashrc and .bash_profile files:

.bashrc

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"

.bash_profile

[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

source ~/.bashrc

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

In the virtual device, I get the error message: Unable to load script from assets index.android.bundle. Make sure your bundle is packaged correctly or you're running a packager server Unable to load script from assets index.android.bundle. Make sure your bundle is packaged correctly or you're running a packager server

I've found two questions on here related to this problem but one of them was using Nuclide and the other guy was using Xcode . Can someone please help with this issue?

Answer and discussion from: https://github.com/realm/realm-js/issues/1448#issuecomment-340757479

The default shell that is opened to run this command doesn't have the NVM node in its PATH. The solution given is to link the existing node install to where the shell expects it to be:

ln -s $(which node) /usr/local/bin/node

You can try running below command:

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

Reference

I was facing the same issue and was using nvm. What I need to do is

nvm alias default v8.15.1

Just to update with someone still having this problem.

I tried all above solutions answer above (and some suggestions from github as well), but neither of them worked for my case (I'm using nvm and node v10.15.3 (TLS))

The final solution I found was to uninstall both nvm & nodejs , then reinstalled nodejs without using nvm via https://nodejs.org/en/download/ .

And it works!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM