初始说明:
"幽灵依赖" 本身原因是 依赖中的依赖(的依赖)被项目工程中引用;切换pnpm后,利用软硬链接 + .pnpm 隔绝了这种不正常的使用方式,导致问题出现;
// vue.config.js
// vue-cli3本身有安装插件,不做package依赖安装
const TerserPlugin = require('terser-webpack-plugin');
// ,.....
// 去掉debugger console.log
new TerserPlugin({
parallel: 3,
exclude: /node_modules/,
terserOptions: {
compress: {
warnings: false,
drop_console: false,
drop_debugger: true,
pure_funcs: ['console.log']
}
}
}),
解决方式一 配置解决
node-linker=hoisted (.npmrc 添加)
给出官网说明:
image.png
优缺点:
1、没有将pnpm特性发挥极致
2、原工程几乎没有任何调整(仅 .npmrc 添加 配置)
解决方式二 依赖解决
由于本身 “幽灵依赖”存在就是缺少依赖包,根据报错,添加依赖包即可
优缺点
1、正常的解题思路
2、可能需要加很多的包再里面
3、可能存在添加了依赖也存在的问题(依赖的依赖,使用了不合适的依赖包,这样需要很大精力去处理)
网友评论