Vue 项目中找不到 NPM 依赖

7

我的vue项目一直运行得很顺利。

我将其中一个组件的文件名更改后出现了错误。我修复了代码并使用npm run serve命令重新启动了npm服务器。

这时我遇到的错误如下:

This dependency was not found:

* vue in ./src/main.js
* router in ./src/vue-router

我通过运行命令成功让路由器重新工作。
npm npm i -D @vue/vue-router

我无法再次让Vue运行起来。我已经尝试过:

 npm install --save vue

但它不起作用。我猜测这是我的webpack配置中的引用错误或其他类似的问题,但我不知道如何修复它。
我的main.js中的代码如下:
import { createApp } from "vue";
import App from "./App.vue";
import router from "vue-router";

我认为这是标准的,并且一直运行良好。

由于这个问题,我的所有开发都停滞了,因此非常需要帮助。

更新

经过一些尝试和重新安装,我已经达到了这个阶段。

嗨,我添加了compiler-sfc,目前,我的package.json看起来像这样:见下文

我还删除了node_modules文件夹,并使用以下命令全部重新安装。

npm install

然而,我仍然遇到这个错误:

Vue packages version mismatch:

- vue@3.0.11 (/Users/delon/Documents/webdev/Vue/amplify_vue3/node_modules/vue/index.js)
- vue-template-compiler@2.6.12 (/Users/delon/Documents/webdev/Vue/amplify_vue3/node_modules/vue-template-compiler/package.json)

This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify should bump vue-template-compiler to the latest.

{
  "name": "amplify_vue3",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build"
  },
  "dependencies": {
    "@aws-amplify/ui-components": "^1.2.0",
    "@vuelidate/core": "*",
    "@vuelidate/validators": "*",
    "aws-amplify": "^3.3.27",
    "core-js": "^3.12.1",
    "vue": "^3.0.11",
    "vue-loader": "^16.2.0",
    "vue-router": "^4.0.0-0",
    "vuelidate": "^0.7.6"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-service": "^3.0.5",
    "@vue/compiler-sfc": "^3.0.11",
    "css-loader": "^5.2.6",
    "file-loader": "^1.1.11",
    "mini-css-extract-plugin": "^0.4.5"
  }
}

我似乎找不到引起问题的参考资料。


当你运行npm install vue时,你说“它不起作用”,发生了什么?你是否收到错误消息?你是否从正确的目录安装? - jeffjenx
嗨,我没有收到错误信息,安装也很顺利,但是当我使用npm serve时,它会给我返回相同的vue依赖项错误,来自main.js文件。 - Delon
@Delon,你有找到解决这个问题的方法吗?我也遇到了同样的问题。 - Rajasekar Gunasekaran
1个回答

0

尝试更新Vue版本和vue-loader@next


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接