vue项目Error: Cannot find module ‘xxx’类报错的解决方法

解决npm模块找不到及GitHub访问失败问题

现发现只要是报错 Error: Cannot find module ‘xxx’(例如 Error: Cannot find module ‘webpack’)这类的问题都可以用下面的方法解决。

报错内容如下:
运行 npm install 没问题,运行 npm run serve 就会报错:

Error: Cannot find module ‘webpack’

解决方案: 

  • 到项目文件夹下,删除 node_modules 文件和 package-lock.json 文件。注意不是package.json(如果删不掉,看下项目是不是打开了,关了再试试)
  • 在项目下运行npm install
  • 继续运行npm run dev(这里不一定是dev,要根据自己实际项目中的配置来,就是启动项目就行)

后面如果报需要安装什么插件,再继续安装插件,重启即可。一定要删除  package-lock.json 不然没有效果!!

安装依赖时错误:fatal: repository ‘https://github.com/nhn/raphael.git/’ not found

vue项目 npm i 安装依赖失败

npm ERR! Error while executing:
npm ERR! d:\Git\cmd\git.EXE ls-remote -h -t https://github.com/nhn/raphael.git
npm ERR! fatal: unable to access 'https://github.com/nhn/raphael.git/': OpenSSL SSL_read: Connection was reset, errno 10054
npm ERR!
npm ERR! exited with error code: 128

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\glq\AppData\Roaming\npm-cache\_logs\2021-08-05T01_57_51_837Z-debug.log

解决方案 1:

当前网络无法访问 github.com ,建议切换为手机热点网络。

解决方案 2:
1、配置淘宝镜像

npm install --registry=https://registry.npm.taobao.org //单次使用

npm config set registry https://registry.npm.taobao.org //永远使用

配置完成后检验是否成功:

npm config get registry //或者下一行

npm info express//或者上一行

2、再次安装

npm i

注意:如果想还原 npm 仓库地址,只需再把地址配置成 npm 镜像就可以了

npm config set registry https://registry.npmjs.org/

参考链接: 

c​​​​​​​​​​​​​ls-remote -h -t https://github.com/nhn/raphael.git npm ERR! fatal: unable to access ‘https://github._oduok的博客-优快云博客
原文链接:https://blog.youkuaiyun.com/sinat_19319243/article/details/119409922

vue项目Error: Cannot find module ‘xxx’类报错的解决方法_晴天'的博客-优快云博客_cannot find module vue
原文链接:https://blog.youkuaiyun.com/weixin_42216142/article/details/87191352

引用[1]:vue项目Error: Cannot find modulexxx报错解决方法_晴天'的博客-优快云博客_cannot find module vue 原文链接:https://blog.csdn.net/weixin_42216142/article/details/87191352 。 引用[2]:问题一:遇到报错信息 Error: Cannot find module ‘D:\project***\node_modules_@vue_cli-service@4.5.12@@vue\cli-service\bin\vue-cli-service.js’ 。 引用[3]:问题二:遇到报错信息 Module parse failed: Unexpected character ‘�’ (1:0) You may need an appropriate loader to handle this file type. (Source code omitted for this binary file) 问题一:处理方案 。 问题:Error: Cannot find module 回答: 当你在Vue项目中遇到"Error: Cannot find module"的报错信息时,这通常是由于缺少模块或路径错误导致的。[1]对于问题一中的报错信息"Error: Cannot find module ‘D:\project***\node_modules_@vue_cli-service@4.5.12@@vue\cli-service\bin\vue-cli-service.js’",可能是由于项目中缺少了vue-cli-service模块或者路径配置错误。解决方法可以尝试以下几步: 1. 确保你的项目中已经安装了vue-cli-service模块,可以通过运行命令"npm install @vue/cli-service"来安装。 2. 检查你的路径配置是否正确,确保路径指向正确的文件或模块。 3. 如果以上方法都没有解决问题,可以尝试删除node_modules文件夹并重新安装依赖,运行命令"npm install"。 对于问题二中的报错信息"Module parse failed: Unexpected character ‘�’ (1:0) You may need an appropriate loader to handle this file type. (Source code omitted for this binary file)",这通常是由于文件型不被正确解析导致的。解决方法可以尝试以下几步: 1. 确保你的项目中已经安装了相应的loader,例如babel-loader或者file-loader,可以通过运行命令"npm install babel-loader"或者"npm install file-loader"来安装。 2. 检查你的webpack配置文件,确保loader的配置正确并且能够处理该文件型。 3. 如果以上方法都没有解决问题,可以尝试更新相关loader的版本或者查找其他解决方案。 希望以上方法能够帮助你解决报错问题。如果问题仍然存在,请参考引用[1]中的原文链接获取更多详细的解决方案。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值