Windows 前端环境配置

486 阅读2分钟

1. 安装NVM

(1)下载安装

下载 nvm 安装包:github.com/coreybutler… image.png

下载完成后解压,然后执行文件夹里面的 nvm-setup 应用程序,按照提示执行下去即可。
中间需要设置 nvm 和 node 的安装目录。

(2)设置国内镜像

nvm node_mirror https://npmmirror.com/mirrors/node/
nvm npm_mirror https://npmmirror.com/mirrors/npm/

参考文档:www.jianshu.com/p/eefd3aa14…

2. 安装Node

  1. 下载地址:nodejs.cn/download/
  2. 安装目录选择:D:\Program Files\nodejs,按照步骤一直 next
  3. 打开 CMD,输入 node -vnpm -v,测试一下是否安装成功
  4. 在安装目录下建立 node_globalnode_cache 两个文件夹,然后执行下面两行命令:
    npm config set prefix "D:\Program Files\nodejs\node_global"
    npm config set cache "D:\Program Files\nodejs\node_cache"
    
  5. 打开环境变量,在 系统变量 下新建 NODE_PATH,输入D:\Program Files\nodejs\node_global\node_modules;把 用户变量Path 值加上 D:\Program Files\nodejs\node_global\

参考文档:juejin.cn/post/684490…

更多内容详见:juejin.cn/post/715684…

3. 安装 Python

官网下载:www.python.org/
选择 Python 2.x 的版本即可,3.x 会有一些兼容性问题。下载之后按步骤安装。

添加环境变量:

  1. 先复制 Python 的安装路径,如我这里是 D:\Program Files\Python2.7.18
  2. 打开环境变量,把上述路径添加进系统变量的 Path

然后再把 Python 执行程序的路径写进 npm 的配置文件中:

npm config get userconfig // 查看 npm 的配置文件地址
把 python=D:\Program Files\Python2.7.18\python.exe 这句写进上述地址

4. 命令行出现没有目录操作权限问题

报错信息:

npm WARN logfile could not be created: Error: EPERM: operation not permitted, open 'D:\Program Files\nodejs\node_cache\_logs\2022-07-07T08_42_34_654Z-debug-0.log'

解决方法:
以管理员身份运行 CMD 即可

5. VsCode 中 npm install 出现权限问题

报错信息:

npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

解决方法:
以管理员方式运行vscode