❤ npm使用以及报错问题归纳和解决方法

最新推荐使用 2024-07 
//切换新源
npm config set registry https://registry.npmmirror.com

// 查看npm镜像地址
npm config get registry

1、npm ERR Error while executing npm ERR CProgram FilesGitcmdgit.EXE ls-remote -h -t sshgit@

问题:

翻译过来就是:
npm ERR执行npm ERRC程序文件时出错Gitcmdgit.EXE ls remote-h-t sshgit@

解决方式:

需要清除DNS

可以清除DNS
执行命令
ipconfig /flushdns

然后执行

使用淘宝镜像
npm install --registry=https://registry.npm.taobao.org

2、This is probably not a problem with npm. There is likely additional logging output above.

问题:

翻译过来就是:
这可能不是npm的问题。上面可能有额外的日志输出。

解决方式:

总结一下常见的几种错误:

1、缺少依赖,如果缺少依赖的话,在最顶上会提示你安装那些缺失的依赖,一开始我也没注意,确实这个提示语提示的信息跟依赖一点关系没有,但确确实实缺少依赖也会报这个错误,大家好好看看错误信息。

2、文件引用错误,文件引用错误也会报这个错,一般也会在最顶上提示你文件的相关信息。

3、node_modules依赖错误问题,如果以上两种方案都没有解决或者说根本没有报文件相关的错误信息的话,那就删除node_modules重新安装,用cnpm 或yarn安装试一下

4、webpack-service版本问题,这个问题博客上有人说过,大家可以自行查找一下相关博客。

5、node版本问题,如果上面还解决不了大家的问题的话,那就重装一个低版本的node试一下,如8.多的版本。

6、如果还有问题的话,那就留言吧,我会帮你一起找其中的问题。
————————————————

3、Rule can only have one resource source (provided resource and test + include + exclude) in …

❤ npm 报错:Rule can only have one resource source (provided resource and test + include + exclude) in {
“exclude”: [

报错原因

翻译过来就是:webpack版本冲突(基本都是webpack5)

解决方法:

1.删除node_modules和package.lock.json
2.重写package.json里webpack的版本号"webpack": “^4.44.2”,

4、cnpm 和不识别es6语法问题,cnpm之后npm run serve 报错

设置淘宝镜像时遇到了cnpm下在vscode无法识别es6语法

1、设置淘宝镜像**

npm config set registry [http://registry.cnpmjs.org](http://registry.cnpmjs.org/)

2、通过npman下载安装cnpm

npm install -g cnpm -registry=https://registry.npm.taobao.org

全局安装了cnpm,然后cmd界面下是正常使用的,但是vscode终端里面没办法正常地使用

3、切换使用国内npm镜像,并且尽量放弃使用cnpm

npm install --registry=https://registry.npm.taobao.org

4、npm instal提示

Could not install from “node_modules\html-pdf-adaptive\node_modules\xxx” as it does not contain a package.json file.

在这里插入图片描述

5、canvas@2.9.3 install: `node-pre-gyp install --fallback-to-build --update-binary

❤ npm 报错 canvas@2.9.3 install: `node-pre-gyp install --fallback-to-build --update-binary

安装canvas

npm install canvas --canvas_binary_host_mirror=https://registry.npmmirror.com/-/binary/canvas

6、 npm install 时报Error: spawn git ENOENT

npm install 时报Error: spawn git ENOENT
在这里插入图片描述

原因:

主要是因为由于 git 的环境变量未设置导致,所以安装一下git 的环境变量就O了,步骤如下:

设置 >> 系统 >> 高级系统设置 >> 高级 >> 环境变量 >> 系统变量:添加一下git 的安装地址

在环境变量的path里添加上 C:\Program Files\Git\cmd 就可以了。路径根据你的git 的安装目录调整

1.重新安装Git
2.环境变量配置path
3.git init

7、 fatal: detected dubious ownership in repository at ‘D:/‘之解决方法

❤ Git 遇到fatal: detected dubious ownership in repository at ‘D:/‘之解决方法

场景:
正常使用GIT 拉取

git pull 
git add .

然后遇到问题:
fatal: detected dubious ownership in repository at ‘D:/‘

解决方法(一):

执行下面代码

git config --global --add safe.directory "*";

解决方法(二):

另外一种方法:
重新git clone +地址 拉取项目
然后把改动过的替换旧的

·解决·

8、 npm不是内部或外部命令,也不是可运行的程序 或批处理文件

❤ npm不是内部或外部命令,也不是可运行的程序 或批处理文件

cmd或者终端用nvm 安装提示: npm不是内部或外部命令,也不是可运行的程序或批处理文件

原因(一)

提示这个问题,有可能是Node没有安装,也有可能是没有配置环境变量
解决方法:

下载Node 或者配置环境变量

我得电脑 》右键属性 》高级系统设置 》环境变量 之中配置nvm 地址和Node 地址

在这里插入图片描述

在这里插入图片描述

原因(二)

下载安装过程很顺利,但是验证node及npm是否安装成功时,出现下面错误提示。

C:\Users\Administrator>npm -v
‘npm’ 不是内部或外部命令,也不是可运行的程序或批处理文件

排查发现node安装目录下只有node_global和node_modules 2个文件夹
在这里插入图片描述

安装nvm后,没有使用管理员身份运行命令窗口
解决办法

卸载nvm,重新安装,使用管理员身份运行命令提示符应用。

在这里插入图片描述

解决成功:
在这里插入图片描述

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐