Vue更新报错排查修复

vue运行报错

报错描述These dependencies were not found

vue前端项目更新以后,运行报错

ERROR  Failed to compile with 5 errors                                                                      下午3:51:42
These dependencies were not found:
* heatmap.js in ./node_modules/[email protected]@babel-loader/lib!./node_modules/[email protected]@vue-loader/lib/sel
ector.js?type=script&index=0!./src/pages/work/problem.vue
* vue-baidu-map/components/map/Map.vue in ./src/main.js, ./node_modules/[email protected]@babel-loader/lib!./node_modu
les/[email protected]@vue-loader/lib/selector.js?type=script&index=0!./src/pages/work/problem.vue
* vue-baidu-map/components/map/MapView.vue in ./node_modules/[email protected]@babel-loader/lib!./node_modules/_vue-lo
[email protected]@vue-loader/lib/selector.js?type=script&index=0!./src/pages/work/problem.vue
* vue-baidu-map/components/search/LocalSearch.vue in ./node_modules/[email protected]@babel-loader/lib!./node_modules/
[email protected]@vue-loader/lib/selector.js?type=script&index=0!./src/pages/work/problem.vue

To install them, you can run: npm install --save heatmap.js vue-baidu-map/components/map/Map.vue vue-baidu-map/component
s/map/MapView.vue vue-baidu-map/components/search/LocalSearch.vue
> Listening at http://localhost:8066

更新代码后,运行"npm run dev" 命令报错,是因为提交地图相关代码,需要插件支持,因此下面开始下载插件

1.下载 heatmap.js

D:\workspace_hbuilder\vue-admin-master>cnpm install --save heatmap.js
√ Installed 1 packages
√ Linked 0 latest versions
√ Run 0 scripts
√ All packages installed (1 packages installed from npm registry, used 346ms(network 343ms), speed 321kB/s, json 1(572B
), tarball 109.54kB)

2.下载 vue-baidu-map

D:\workspace_hbuilder\vue-admin-master>cnpm install --save vue-baidu-map
√ Installed 1 packages
√ Linked 12 latest versions
√ Run 0 scripts
peerDependencies link [email protected] in D:\workspace_hbuilder\vue-admin-master\node_modules\[email protected]@vue-baidu
-map unmet with D:\workspace_hbuilder\vue-admin-master\node_modules\vue(2.6.11)
Recently updated (since 2020-08-19): 1 packages (detail see file D:\workspace_hbuilder\vue-admin-master\node_modules\.re
cently_updates.txt)
√ All packages installed (11 packages installed from npm registry, used 1s(network 1s), speed 896.03kB/s, json 13(59.31
kB), tarball 1.07MB)

vue 打包报错ERROR in xx.js from UglifyJs

ERROR in static/js/1.b1bd2364d7d04826fb20.js from UglifyJs
Unexpected token: operator (>) [./node_modules/[email protected]@vue-baidu-map/components/base/mixins/common.js:16,
0][static/js/1.b1bd2364d7d04826fb20.js:40844,30]

ERROR in static/js/vendor.96c0ded070a832778c51.js from UglifyJs
Unexpected token: operator (>) [./node_modules/[email protected]@vue-baidu-map/components/base/bindEvent.js:5,0][st
atic/js/vendor.96c0ded070a832778c51.js:49854,26]
  Build failed with errors.

1.错误原因

在 UglifyJs 的 github issues #78 找到了这样一个解决方案:由于 UglifyJs 只支持 ES5 而 element-ui 可能引入了一部分 ES6 的写法,所以导致 webpack 打包失败。 issue 里最后给出的解决方案是用 beta 版本的Uglify-es 来代替 UglifyJs(Beta 版本引入了对 ES2015+)的支持。需要在前端工作目录下用执行命令

cnpm i -D uglifyjs-webpack-plugin@beta

2.错误解决

修改前端文件夹下的build/webpack.base.conf.js 文件即可,修改如下: 修改前

module: {
rules: [
...
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test')]
},
...]
}

修改后

module: {
rules: [
...
{
test: /\.js$/,
loader: 'babel-loader',//注意elementUI的源码使用ES6需要解析
include: [resolve('src'), resolve('test'),
resolve('/node_modules/[email protected]@vue-baidu-map')  // <<------ add code
]
},
...]
}

相当于将 element-ui 加入需要 babel 解析的包中,之后再次执行 npm run build, build 成功。

参考:https://blog.csdn.net/sing_sing/article/details/79146265?utm_source=blogxgwz6

参考:https://www.cnblogs.com/learnoffs/p/7872154.html

参考:https://blog.csdn.net/Uncle_long/article/details/80336680

快速删除node_modules

这个node_modules目录,在windows上删除特别慢,跟中病毒似的。处理方法如下:

1.安装rimraf

在全局安装rimraf模块:

D:\workspace_hbuilder\vue-admin-master>cnpm install rimraf -g

2.命令删除

然后通过其命令来快速删除node_modules目录

D:\workspace_hbuilder\vue-admin-master>rimraf node_modules

3.下载

重新环境支持:下载node_modules环境

D:\workspace_hbuilder\vue-admin-master>cnpm install

4.运行vue

D:\workspace_hbuilder\vue-admin-master>npm run dev

参考node_modules目录删除方法:https://www.cnblogs.com/25miao/p/12706845.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章