node.js 安装

如果电脑有node.js 版本就先安装依赖试试,如果不成功,则参考指定版本

如果想管理多个版本的node.js 则可以参考nvm 安装

下载与安装

node.js下载 选择 某个版本, 比如 v18.20.2 (LTS)
在这里插入图片描述

  • 安装完后 cmd里输入 node -v 验证是否安装成功和当前版本号
  • node 自带npm 使用npm -v 查看 版本
    在这里插入图片描述

安装位置修改(不重要)

  • 全局模块所在的路径,以及缓存cache的路径(先创建文件)
npm config set prefix D:\java\node\node_global
npm config set cache D:\java\node\node_cache
  • 修改环境变量
将C:\Users\Administrator\AppData\Roaming\npm
替换为D:\java\node\node_gobal

npm

依赖安装命令 (推荐)

推荐直接使用 --registry

# 临时使用
npm install --registry https://registry.npmmirror.com
# 或者
npm install --registry=https://registry.npmmirror.com --force

# 永久设置
npm config set registry https://registry.npmmirror.com
npm config get registry

cnpm (不推荐)

npm 镜像站

npm install -g cnpm --registry=https://registry.npmmirror.com
cnpm -v

在这里插入图片描述

pnpm

参考 pnpm 基本详细使用教程(安装、卸载、使用、可能遇到的问题及解决办法)

# 安装
npm install -g pnpm --registry=https://registry.npmmirror.com
# 设置镜像地址
pnpm set registry https://registry.npmmirror.com

安装位置设置

# 允许设置全局安装包的 bin 文件的目标目录。
pnpm config set global-bin-dir "D:\java\nvm\pnpm-cache"
# 包元数据缓存的位置。
pnpm config set cache-dir "D:\java\nvm\pnpm-cache"
# pnpm 创建的当前仅由更新检查器使用的 pnpm-state.json 文件的目录。
pnpm config set state-dir "D:\java\nvm\pnpm-state"
# 指定储存全局依赖的目录。
pnpm config set global-dir "D:\java\nvm\global"
# 所有包被保存在磁盘上的位置。
#(可选,以下这条命令可以选择不执行也是OK的)
pnpm config set store-dir "D:\java\nvm\pnpm-store"

# 查看配置
pnpm c list

nvm 管理 (进阶,可以不管的)

如果需要管理nvm 版本的话,可以参考这个

nvm 一个nodejs版本管理工具! 下载地址

官方下载地址

参考【工具】用nvm管理nodejs版本切换,真香! 设置步骤,
建议使用 nvm-setup.zip 安装

  • 设置 %NVM_HOME%NVM_SYMLINK
  • 验证
# 验证
nvm -v
  • 配置文件 在 nvm 的安装路径下,找到 settings.txt (没有就创建)

参考 nvm-noinstall 官方文档 https://github.com/coreybutler/nvm-windows/wiki

root: D:\java\nvm
path: D:\java\nodejs
arch: 64
proxy: none
npm_mirror: https://npmmirror.com/mirrors/npm/
node_mirror: https://npmmirror.com/mirrors/node/

https://github.com/coreybutler/nvm-windows/blob/60d4312fbe78132f1bc545c8e986ba72a7a5232e/src/nvm.go#L40
注意:D:\java\nodejs 需要不存在,因为这个需要使用软连接

在这里插入图片描述

  • 查看
nvm list available 

在这里插入图片描述

命令

# 下载nodejs 20.9.0
nvm install 12.22.12

# 版本切换
nvm use 12.22.12
# 列出所有已经安装的版本
nvm ls 
# 显示当前使用的版本
nvm current 
# 设置默认 node 版本
nvm alias default 
# 解除当前版本绑定
nvm deactivate 
# 卸载指定的版本
nvm uninstall 12.22.12

参考

node-sass 坑

node-sass 根据电脑环境不同,下面解决方式不一定有效

低版本node 通过换源解决

node-sass和版本对应关系

# 查看本地node版本
node -v

# 安装node-sass
npm install  --registry=https://registry.npmmirror.com --sass_binary_site=https://www.npmmirror.com/mirrors/node-sass/

node 18

更换 对应依赖,

"node-sass": "^8.0.0",
"sass-loader": "^10.4.1",

node 18 不支持 sass_binary_site选项
在这里插入图片描述
也会报其他环境问题

npm ERR! gyp info using node-gyp@8.4.1
npm ERR! gyp info using node@18.20.2 | win32 | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb find Python Python is not set from command line or npm configuration
npm ERR! gyp verb find Python Python is not set from environment variable PYTHON
npm ERR! gyp verb find Python checking if "python3" can be used
npm ERR! gyp verb find Python - executing "python3" to get executable path
npm ERR! gyp verb find Python - "python3" is not in PATH or produced an error
npm ERR! gyp verb find Python checking if "python" can be used
npm ERR! gyp verb find Python - executing "python" to get executable path
npm ERR! gyp verb find Python - executable path is "D:\python\python.exe"
npm ERR! gyp verb find Python - executing "D:\python\python.exe" to get version
npm ERR! gyp verb find Python - version is "3.10.9"
npm ERR! gyp info find Python using Python version 3.10.9 found at "D:\python\python.exe"
npm ERR! gyp verb get node dir no --target version specified, falling back to host node version: 18.20.2
npm ERR! gyp verb command install [ '18.20.2' ]
npm ERR! gyp verb install input version string "18.20.2"
npm ERR! gyp verb install installing version: 18.20.2
npm ERR! gyp verb install --ensure was passed, so won't reinstall if already installed
npm ERR! gyp verb install version is already installed, need to check "installVersion"
npm ERR! gyp verb got "installVersion" 9
npm ERR! gyp verb needs "installVersion" 9
npm ERR! gyp verb install version is good
npm ERR! gyp verb get node dir target node version installed: 18.20.2
npm ERR! gyp verb build dir attempting to create "build" dir: D:\vscode\order\ths0108\source\hotel-client-admin\node_modules\node-sass\build
npm ERR! gyp verb build dir "build" dir needed to be created? Yes
npm ERR! gyp verb find VS msvs_version not set from command line or npm config
npm ERR! gyp verb find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp verb find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
npm ERR! gyp verb find VS looking for Visual Studio 2015
npm ERR! gyp verb find VS - not found
npm ERR! gyp verb find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
npm ERR! gyp ERR! find VS looking for Visual Studio 2015
npm ERR! gyp ERR! find VS - not found
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error

替换成Dart-sass 推荐

npm install node-sass@npm:dart-sass -D
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值