简体   繁体   中英

TypeError: Cannot destructure property `stat` of 'undefined' or 'null'

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)

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

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).

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.

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

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

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