MacOS配置nvm,node,npm的问题

配置环境:MacBook Pro(M1,2020)
在mac终端执行:

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
...
$ nvm install 14.17.1
$ nvm --help
$ node --help
$ npm --help

发现,出现如下错误:zsh:command not found:nvm,且关闭终端之后重启终端,依然出现zsh:command not found:nvm

A1:
将执行curl之后完成之后生成的如下脚本加入到 ~/etc/zshrc中,保存退出,source执行即可。

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Q2:npm install无效的问题(前提:已配置好npm私有源)
$ npm install --global xxxxxxxxxxxxx(formula下载,在nvm 14中执行)

出现错误:

A2:解决方案,且需要切到nvm16.16.0进行操作

nvm use 16
nvm use 14

Q3:nvm14与nvm16下,路径不统一导致formula不共享

A3:

$ npm config set prefix /usr/local //v16.16.0
$ npm config set prefix /usr/local.//v14.20.0

Q4:nvm14、nvm16需要手动切换,如果不切换到16,formula不能下载问题:

A4:

1. arch
2. softwareupdate --install-rosetta
3.arch -x86_64 zsh
4.source "${NVM_DIR}/nvm.sh"
5.nvm install v14.20.0 --shared-zlib(需要手动切到16先进行卸载:nvm uninstall 14

问题分析:
MacBook Pro搭载的M1芯片在nvm14和nvm16之间未完成路径间的兼容(个人理解),需手动更改路径,前提查看node_moudles的路径是否为/usr/local/…,详细解答欢迎大家查看此链接:
Zlib error when attempting to run npm install or yarn

npm WARN deprecated @types/[email protected]: This is a stub types definition. next-auth provides its own type definitions, so you do not need this installed.
npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm ERR! code Z_DATA_ERROR
npm ERR! errno -3
npm ERR! zlib: incorrect data check

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/niltonsf/.npm/_logs/2021-10-05T15_44_51_340Z-debug.log
niltonsf@Niltons-MacBook-Pro ignews.nosync % 

你可能感兴趣的:(前端配置,配置专栏,npm,macos,前端)