配置 npm npm config set registry https://registry.npmmirror.com npm config delete registry npm config get registry npm config get cache npm install -g npm@latest
配置 Yarn npm i -g yarn yarn config set registry https://registry.npmmirror.com yarn config delete registry yarn config get registry yarn cache dir
注意,现在默认安装的还是 v1 的 yarn
;从 2.0 开始有很大的改变: 不再提供 yarn global
相关的指令,也就是说全局包需要使用 npm i -g
来安装; 不再提供 yarn create
之类的指令,需要使用 yarn dlx
。
配置 pnpm npm i -g pnpm pnpm config set registry https://registry.npmmirror.com pnpm config delete registry pnpm config get registry pnpm config get store-dir
遇到 sass 等库安装失败 node-sass
容易出错,新项目建议换用 sass(也就是 dart-sass)。 如果是老项目没法换,以下方法选择一个即可:
方法1:
在项目根目录创建 .npmrc
文件,写入以下内容:
sass_binary_site =https://npmmirror.com/mirrors/node-sass/
或者全局配置 npm 和 yarn:
npm config set sass-binary-site https://registry.npmmirror.com/node-sass yarn config set sass-binary-site https://registry.npmmirror.com/node-sass
方法2:
使用 cnpm
来安装依赖:
Git 相关 ssh-keygen -t rsa -b 4096 -C "git" ssh-keygen -p git remote add <名称> <地址> git remote set-url --add <名称> <远程地址>
设置用户名和邮箱 git config user.name "username" git config user.email "mail@domain.com" git config --global user.name "username" git config --global user.email "mail@domain.com" git config user.name git config user.email
设置代理 git config --global http.proxy http://127.0.0.1:7890 git config --global https.proxy http://127.0.0.1:7890 git config --global --unset http.proxy git config --global --unset https.proxy
Windows 换行符问题 git config --global core.autocrlf false git config --global core.autocrlf input
macOS 常用命令 sudo chown -R $USER /usr/localexport http_proxy=http://127.0.0.1:7890export https_proxy=http://127.0.0.1:7890 sudo vim /etc/hosts
Windows 常用命令 set-ExecutionPolicy RemoteSigned bcdedit /set hypervisorlaunchtype auto bcdedit /set hypervisorlaunchtype off ipconfig /flushdns notepad c:\windows\system32\drivers\etc\hosts
端口占用问题 netstat -ano | findstr "3000" net stop winnat net start winnat netsh winsock reset
注意,上文中一部分指令标注了 “WSL 用户请勿执行” 的指令,如果执行了,请重启电脑,单纯重启 WSL 是仍然无法联网的。
WSL 用户遇到端口被占用,但是查不到进程时;或者是 Docker 用户遇到 permission denied 0.0.0.0:3000
这类端口问题时,参考以下解决方法:
Windows 系统存在一种 “TCP 动态端口范围” 的名词,这个范围内的端口号有时会被一些服务占用。Windows Vista 和以前的系统,这个范围是 1025
- 5000
;之后的操作系统,这个范围是 49152
- 65535
;我们现在用的都是 Windows 10、11,所以基本不再会收到这些影响了。
而且,如果启用了 Hyper-V,它也会保留一些随机端口号供 Windows 容器主机网络服务使用,它预留的端口号一般都很大,不太会对用户造成影响。但是 Windows 自动更新有时会出错(万恶的自动更新),把 “TCP 动态端口范围” 起始端口被重置为 1024
,导致 Hyper-V 在预留端口的时候占用了常用端口号,使得一些常用端口因为被预留而无法使用。
查看当前的 “TCP 动态端口范围”:
netsh int ipv4 show dynamicport tcp
解决方法:
netsh int ipv4 set dynamic tcp start=49152 num=16384 netsh int ipv6 set dynamic tcp start=49152 num=16384
执行后,请重新启动电脑。
此外,操作系统会保留一部分端口,这个指令可以查看哪些端口号被保留:
netsh interface ipv4 show excludedportrange protocol=tcp