3
votes

I am getting a TypeError when running npm install -g react-native project on mac.

full error

TypeError: Cannot destructure property stat of 'undefined' or 'null'. at Object. (/usr/local/lib/node_modules/npm/node_modules/@npmcli/node-gyp/lib/index.js:2:29)

5
Does this answer your question? How to initialize React Native projectRandy Casburn
it doesn't work, It even not allow me to run npm installSri ram kathirvel
it would seem that your problem is not with react native then. Rewrite your question to include the error messages associated with running node and npm - not react native.Randy Casburn
It works after deleting and re install node.js manually, previously I used this cmd 'brew install node' for installing node.Sri ram kathirvel
I installed macOS Big Sur, and I have this issue now (on projects that used to work fine before that update). Maybe it's related, I'm still investigating.Axel Rock

5 Answers

2
votes

Might be you are using npm@latest. Looks to me some issue with lates NPM, I have changed my version with RUN npm install [email protected] -g in my docker file working for me.

2
votes

When I upgraded to Big Sur, I had the same issue. It's something to do with npm, not react-native.

Here's what I did to solve the problem:

Delete everything related to nodejs:

sudo rm -rf ~/.npm ~/.nvm ~/node_modules ~/.node-gyp ~/.npmrc ~/.node_repl_history
sudo rm -rf /usr/local/bin/npm /usr/local/bin/node-debug /usr/local/bin/node /usr/local/bin/node-gyp
sudo rm -rf /usr/local/share/man/man1/node* /usr/local/share/man/man1/npm*
sudo rm -rf /usr/local/include/node /usr/local/include/node_modules
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /usr/local/lib/dtrace/node.d
sudo rm -rf /opt/local/include/node /opt/local/bin/node /opt/local/lib/node
sudo rm -rf /usr/local/share/doc/node
sudo rm -rf /usr/local/share/systemtap/tapset/node.stp

brew uninstall node
brew doctor
brew cleanup --prune-prefix

And then install nvm again via:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash

Now, I was able to install all of my dependencies since now I've got a fresh copy of npm(for me it was 6.4.1).

1
votes

As usual, Mac OS updates tend to break stuff.

In case you're using NVM too (like me). I faced this issue too and found that NVM is using a node version called 'system'. I never seen it before and NVM should be using the version I set it to use.

So I decided to update NVM. (See: https://github.com/nvm-sh/nvm/blob/master/README.md#installing-and-updating)

Seems to work after that.

0
votes

You shouldn't be using npm install -g react-native.

Please read through the React Native docs on how to do your environment setup: https://reactnative.dev/docs/environment-setup

0
votes

In case that you have the same error when running any command that has npm, you might have wrong npm version with node 8.

Running this will reverse your npm to node 6.

curl -qs https://www.npmjs.com/install.sh|npm_install=6.14.11 sh

Reference: https://github.com/npm/cli/issues/2599