React Native Fails To Start Server With Error In #react-native-community/cli/build/commands/doctor/healthchecks/index.js - react-native

I just created a brand new React Native project, and I can't get it to run. The server always fails on the following:
node_modules/react-native/node_modules/#react-native-community/cli/build/commands/doctor/healthchecks/index.js:48
} catch {}
^
SyntaxError: Unexpected token {
The only thing I've found on this issue is this thread, which ends with people saying to post this question on Stackoverflow, hence why I'm here. I've tried the usual: upgrading node versions, removing node_modules and reinstalling, restarting my machine, all to no avail. I even delved into the code to see if I could figure out what's going on, but nothing jumped out at me.
My hope is that others have run into this with new React Native projects and that someone can help me resolve it. Any suggestions are welcome. Thanks!

Sigh.... Well after struggling with this for a day I found the workaround was to run npx react-native start in one console and then run npx react-native run-ios in another. I was just trying to do the latter by itself (which always worked in the past), and I guess that doesn't work anymore.

Probably your node and/or npm version is to old. Check by npm -v and node -v and update to latest version, or suggesting by react-native crew in dependencies from node site. Or if you use nvm try:
nvm install 16.14.0 && nvm alias default 16.14.0 && nvm use 16.14.0
Note that, this is for specific version. For latest, type:
nvm install --lts --latest-npm
nvm use x.x.x //latest installed version

This problem is due to node version. Upgrade your node verion above 12. It will solve the problem.
Use can either use nvm or directly install the node

if you are using android studio start it with command line
like this cd /path/to/android-studio/bin
then studio.sh make sure its executable

Related

npm run dev not working with sveltekit/vite project

whenever i run this command: npm run dev, I get the following error. this is a sveltekit and vite (which i'm very new to) project.
> my-app#0.0.1 dev
> vite dev
failed to load config from /home/believe/Documents/my-app/vite.config.js
error when starting dev server:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '#sveltejs/kit' imported from /home/believe/Documents/my-app/vite.config.js.timestamp-1659118538332.mjs
at new NodeError (node:internal/errors:363:5)
at packageResolve (node:internal/modules/esm/resolve:698:9)
at moduleResolve (node:internal/modules/esm/resolve:739:18)
at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:853:11)
at Loader.resolve (node:internal/modules/esm/loader:89:40)
at Loader.getModuleJob (node:internal/modules/esm/loader:242:28)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:73:40)
at link (node:internal/modules/esm/module_job:72:36)
IMHO, using / switching-to the latest version of node should ideally resolve this issue. I had faced this error, and switching to the latest version of node is what worked for me.
I have found that installing the nvm (node version manager) cli package is one of the best and handy ways to address and handle such situations. This is because, it will let you install and manage multiple versions of node, so that you can switch node versions, between projects, as needed per relevant dependencies.
For eg., in this case, I would just say nvm use latest in the project cli, and nvm will switch to the latest node version (if/where installed ==> node v18.7.0 w/ npm 8.15.00 as of now, for me, for eg. ).
At that, nvm ls lists all the installed node versions on that system/ environment, and points to the one in use at the moment. Very handy!
More info on nvm here: http://nvm.sh/
[* Since you have not mentioned the OS/ENV and Terminal etc., I can not unfortunately (at this time) share specific install instructions, and am hence pointing to the nvm git. Hope you understand. :) ]
Hope this helps; have a nice day! :)

Warning: Invalid version react-native#0.64.2 for expo sdkVersion 43.0.0. Use react-native#0.64.3

I am working on an expo project and everything is working fine, but I began to get a warning message when android is building as
Warning: Invalid version react-native#0.64.2 for expo sdkVersion 43.0.0. Use react-native#0.64.3
The app is still running fine but I don't how to fix this error yet and I want to know if it won't cause an issue later.
I have tried to run npx react-native upgrade 0.64.3 but it didn't work, I got this error
info Fetching diff between v0.64.2 and v0.64.3... error Fetch request
failed with status 404: 404: Not Found. error Failed to fetch diff for
react-native#0.64.3. Maybe it's not released yet?
changing the version of react-native manually in the package.json and run expo install worked for me
I use the expo doctor command it allows diagnose issues with the project.
I would recommend using the expo upgrade command. It upgrades the project packages and config for the given SDK version.
More to find here.
I just faced the same issue. Basically it's telling you should use a higher version of your react-native. I solved it just by updating it to the specified version.
npx react-native upgrade 0.64.3
More info here.
Cheers,
If as in my case one need a specific version of react-native, let's say older because some legacy dependencies in a particular project that for some reason can't be upgrade, then change the version in the package.json won't work.
What worked as the cli suggested is to use:
expo doctor --fix-dependencies
That installed the correct lower version of react-native
To find out actual problems run this command :
expo doctor
To solve all problems regarding package conflicts run this command:
expo doctor --fix-dependencies
Use sudo on Unix based OS if you have permission issue to run those commands.
To solve the error, I used the below command:
npm install react-native-clean-project --save-dev
It is a library that allows us to resolve conflicts.
This library is added to your dependencies.
This handles the problem and if it is not the case add this command:
react-native clean-project-auto

NVM breaks sporadically because of resetting PREFIX environment variable

The Problem
I am trying to run a react-native iOS application from the CLI. This has not been a problem in the past, but haven't developed in react-native for over 6 months. Last week in about 40% of the cases when a (zsh) terminal is opened nvm breaks because of the environment variables. This could happen whether I open the terminal myself, or when VSCode opens a new terminal for the metro bundler. Running from Xcode always works. Closing all zsh terminals and then opening a new one seems to resolve the issue. Additionally, it happens (more) often in the terminal that is opened by VSCode for the metro bundler than when I open the terminals myself. Lastly, the issue seems to 'stick' once it starts occurring I need to close all terminals for the error to be resolved.
Error that is shown
nvm is not compatible with the "PREFIX" environment variable: currently set to "/usr/local"
Run `unset PREFIX` to unset it.
nvm is not compatible with the "PREFIX" environment variable: currently set to "/usr/local"
Run `unset PREFIX` to unset it.
What I have tried
Changing environment variables
1.1 When the zsh terminal does NOT show the error:
I tried running npm config delete prefix, in hopes of changing the config so that the issue does not pop up anymore. I can't run this command when the error is shown, because I have no access to node or npm.
1.2 When the zsh terminal does show the error:
I can 'fix' the terminal by unsetting the PREFIX variable with unset PREFIX and then asking nvm to use a version of node. However this only fixes that particular instance of the terminals. The only sure fire way is to close all terminals.
unset PREFIX
nvm use v14.15.0
Updating react-native
Speaks for itself, a colleague mentioned that it might be caused by a bug in react-native. Did not resolve the issue unfortunately.
Conclusion
It seems as though something (re)triggers setting the PREFIX environment variable when I try to run the react-native iOS project. I am honestly completely lost as to what might be causing this and any help would be truly appreciated.
I had this issue too, as have others.
Are you using yarn or npm to run the React Native CLI? If so, and these were installed with Homebrew, these might be conflicting with your nvm installed node. Try removing these:
brew uninstall yarn
brew uninstall npm
This should leave behind the version of npm that was installed with nvm, check this by running:
which npm
This should return a path pointing to your local .nvm installation. If it shows /usr/local then it was not removed correctly, you might need to follow the npm removal instructions.
Once this is done, if you use yarn then install it with npm:
npm install -g yarn
Run the React Native CLI once again, it should now work.
More details on this resolution: https://github.com/nvm-sh/nvm/issues/1645#issuecomment-850376572

Error: option 'name' clashes with existing property 'name' on Command

Some context: I've recently been trying to update a react native project that uses expo, since I have not worked on the project for about four months. I believe I finally was able to successfully upgrade the project as expo is starting. The issue is that I am now having some trouble with some of the newer modules I just installed with npm. This error seems to be coming from me not knowing how to use the commander module. Additionally, I do not believe that I have a thorough understanding of modulues in react native/expo. I am using ubuntu 20.04 via windows terminal.
Error:
I did go to the website mentioned in the error. I believe that this link - https://github.com/tj/commander.js#avoiding-option-name-clashes - is what will solve my problem. However, I am confused as to where I should put the example file and how to use it.
I am not very well versed in modules for react native/expo and it is quite possible that I do not need to use this module (I thought that installing it would make my react native program run, but that does not seem to be the case).
Thus, I am looking for advice on either how to use this module, or on whether or not I should be using these modules (after updating node and then expo, the following modules could not be found every time I ran npm start, so I decided to install them using sudo npm install module_name -g since some other stackoverflow/github pages recommended that):
fs-extra
terminal-link
chalk
getenv
commander
#expo/xdl
Any help would be appreciated, and I would be happy to provide any more information that would be relevant.
I was not able to figure out a way to make the project work with the above modules. So, I followed the advice of a post I made on the expo forums (I posted similar context there and also the answer that I wrote below).
If you do not want to click the link, here are the steps below:
Basically, I uninstalled expo using the following command: npm -g uninstall expo-cli --save && yarn global remove expo-cli. Then I proceeded to remove the .expo folder from my home directory. More details on these two steps can be found here.
After that, I reinstalled expo using npm install --global expo-cli, from the expo documentation, in the install section.
Then I closed my terminal, reopened it, and ran expo whoami. The command returned recommending an update, so I followed the provided update command (which I believe was just npm install --global expo-cli again).
I closed the terminal, reopened it, and ran expo whoami again. This time I was just met with "you are not logged into expo" (or something along those lines). So, everything seemed up to date.
I then went to project and ran npm start and it worked fine.
Note: You may need to use sudo for any uninstall and install commands above (your terminal will likely tell you if you do).
Note Clearing cache for npm and yarn may take some time. Additionally, the first time you run npm start may also take some time. I'd say all in all this took about two to three hours, but my computer is also not the best.

expo always returning me with "-bash: expo: command not found" everytime i go to set up a project, "expo init projectname". how do i resolve this?

have downloaded latest version of node.js on mac
terminal says ive downloaded latest version of expo cli
if i try to run my first project in terminal; expo init project name, am always met with the same error. -bash: expo: command not found.
when i check terminal to make sure that expo is installed, i am also met with: -bash: expo: command not found.
i have spent at least 3 days trying to resolve this problem.
any help towards this resolution would be greatly appreciated
How have you downloaded the Expo CLI? It may be important to note that if you don't install the package globally, like npm install -g expo-cli, it may not be properly executable.
[Additionally, One thing I've found when installing commands is that it can help to restart your terminal. Sometimes after you've installed something new, not everything will be in place, but it might be there when the terminal restarts.]