error in ./node_modules/vue-router/dist/vue-router.mjs“export ‘computed‘ was not found in ‘vue‘

 

错误日志

 ERROR  Failed to compile with 47 errors                                                                                
 error  in ./node_modules/vue-router/dist/vue-router.mjs

"export 'computed' was not found in 'vue'

 error  in ./node_modules/vue-router/dist/vue-router.mjs

"export 'computed' was not found in 'vue'

 error  in ./node_modules/vue-router/dist/vue-router.mjs

"export 'computed' was not found in 'vue'

 error  in ./node_modules/vue-router/dist/vue-router.mjs

错误截图

错误原因

npm自动下载vue-router时下载的是最新版(vue-router版本太高和vue2起冲突了)

在package.json中找到

解决方法

卸载4版本的router 安装指定版本的vue-router即可,可以安装3.5.2 的vue-router(亲测可用 )

卸载命令:npm uninstall vue-router
安装命令:npm i vue-router@3.5.2

最后重新启动项目即可

WARN "css.modules" option in vue.config.js is deprecated now, please use "css.requireModuleExtension" instead. INFO Starting development server... 98% after emitting CopyPlugin WARNING Compiled with 17 warnings 09:43:57 warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'computed' was not found in 'vue' warning in ./src/router/index.js "export 'default' (imported as 'VueRouter') was not found in 'vue-router' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'defineComponent' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'getCurrentInstance' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'h' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'inject' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'nextTick' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'onActivated' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'onDeactivated' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'onUnmounted' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'provide' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'reactive' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'ref' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'shallowRef' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'unref' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'watch' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'watchEffect' was not found in 'vue'这个报错因为什么
06-09
### 正确配置和使用 Vue Router 对于 Vue 项目的正确配置和使用 Vue Router,特别是针对 `vue-router.mjs` 文件可能引发的问题,有几点需要注意。 #### 版本兼容性 确保所使用的 VueVue Router 的版本相互兼容。如果遇到错误提示如 `error in ./node_modules/vue-router/dist/vue-router.mjs`[^2] 或者其他类似的模块解析失败问题,则可能是由于 Vue Router 版本过高或过低造成的不匹配。建议先尝试安装特定稳定版的 Vue Router 来解决问题,例如通过命令 `npm install vue-router@3.5.2` 可以指定安装较稳定的 3.x 版本[^4]。 #### 配置文件调整 在 Vue Router 4.x 中,一些 API 发生了变化,比如 `<router-view>` 组件不能再像以前那样直接放置于模板内[^3]。为了适应这些改动,在创建路由实例时应当按照新版文档说明来进行设置: ```javascript import { createRouter, createWebHistory } from 'vue-router' // 导出路由表... const router = createRouter({ history: createWebHistory(), routes, }) export default router; ``` 此外,若要实现条件性的缓存功能(即基于 meta 字段),则需利用组合式 API 提供的新特性——动态组件加作用域插槽的方式替代旧有的写法。 #### 处理打包工具相关报错 有时会因为 Webpack 或 Vite 等构建工具的原因而出现诸如 `ReferenceError: parcelRequire is not defined` 这样的异常情况[^5]。这通常意味着存在环境变量缺失或者是某些依赖项未被正确加载的情况。此时应该检查项目中的入口脚本标签是否正确设置了类型属性 (`type="module"`),并确认所有必要的 polyfill 已经加入到编译流程当中去。 综上所述,解决 Vue Router 模块引入问题的关键在于保持库之间的良好协作以及遵循最新版本的最佳实践指南。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值