nodejs环境配置
文章目录
1.系统环境变量
NODE_PATH=C:\nodejs\node_global\node_modules
// Path系统环境变量追加以下内容
Path = ;C:\Program Files\nodejs;C:\nodejs\node_global
C:\Program Files\nodejs
node命令位置;
C:\nodejs\node_global
node安装的第三方命令(如:cnpm、webpack、vue)位置;
2.配置
npm config set prefix "C:\nodejs\node_global"
npm config set cache "C:\nodejs\node_cache"
npm config set registry=https://registry.npmmirror.com
npm config ls
npm install -g cnpm
npm install -g yarn
yarn -v
yarn config set registry https://registry.npmmirror.com
yarn config list
npm install -g cnpm
cnpm -v
npm install @vue/cli -g
vue -V
cnpm install node-sass --save
node-sass -v
- 改回官方配置
npm config set registry https://registry.npmjs.org
yarn config set registry https://registry.yarnpkg.com
3.使用nrm管理源
npm install-g nrm
nrm ls
nrm test taobao
nrm use taobao
4.使用nvm切换nodejs版本
切换node版本时,推荐使用“以管理身份运行”
原理:移除系统环境变量中nodejs路径,创建NVM_SYMLINK
环境变量指向nvm use
指定版本的软链接(快捷方式
)上。
nvm -v
nvm ls
nvm install latest
nvm install lts
nvm current
nvm use lts
nvm current
nvm use 16.13.0
nvm current
10.问题
(1) node-gpy rebuild失败
- 问题描述
执行
npm install
时提示node-gpy rebuild
失败
- 解决办法
下载最新版本Node.js安装包并安装,勾选
Tools for Native Modules
页的复选框,自动安装Python
和Visual Studio Build Tools
(推荐自动安装,避免Python或Visual Studio Build Tools版本不匹配问题)
(2) node-sass从github下载不了
npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
- .npmrc
phantomjs_cdnurl=http://cnpmjs.org/downloads
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
registry=https://registry.npm.taobao.org
另外注意node-sass和nodejs版本依赖关系
参考:
webstorm 设置 npm 环境
使用nrm切换npm源
整理 node-sass 安装失败的原因及解决办法
node和node-sass版本问题