Skip to content

Node环境小问题集 持续更新

简述

工作中遇到的很多小问题,解决了但是疏于整理,导致重复问题重复仍需百度搜索,特有此记录小问题。

nrm 安装成功但运行失败

找到并打开这个文件

sh
C:\Users\你的用户名\AppData\Roaming\npm\node_modules\nrm\cli.js

将第十七行换成下面这个

js
const NRMRC = path.join(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], '.nrmrc')

如果你的nrm 安装不上,查看是否有权限问题,或者是npm 缓存问题

devDependencies与dependencies区别

前者目录下的包仅用于开发环境,打包时不会被打包。后者开发与线上均在使用。

前者安包参数为 --save-dev或-D 后者安包参数为 --save或-S

-D-S必须大写

解决VSCODE"因为在此系统上禁止运行脚本"报错

执行后关闭当前命令行窗口,另打开一个即可

js
// 执行
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

解决 LF CRLF 导致的项目警告与格式报错

导致这个的原因是git默认设置的换行方式是LF,需要设置一下git,然后重新下载一下项目,就ok了

js
git config --global core.autocrlf false

解决更改文件名带小写,被git忽略

js
git config core.ignorecase false

解决 node-gyp 安装东西报错,并提示安装VS和C++

具体报错如下

js
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

解决方法:以管理员身份打开PowerShell,运行以下命令

js
npm install --global --production windows-build-tools

引入package.json

js
import pkg from "./package.json" assert { type: "json" };

更新于:

夜茶 2020 ~ 2026