npm忽略冲突依赖

51 阅读1分钟

背景

公司有个很老的项目,使用Webpack3搭建的,里面有些私有库已经不维护了。 今日打算给项目安装webpack-bundle-analyzer

    npm install --save-dev webpack-bundle-analyzer

但是报错了: npm ERR! code E404 npm ERR! 404 Not Found - GET registry.npmjs.org/wl-intl - Not found npm ERR! 404 npm ERR! 404 'wl-intl@1.0.7' is not in the npm registry. npm ERR! 404 You should bug the author to publish it (or use the name yourself!)

很疑惑,我安装webpack-bundle-analyzer这个插件,又不是执行npm install全部安装,为什么会检查wl-intl这个私有库呢?而且这个私有库是存在于node_modules中的。

问了下AI,得知运行 npm install --save-dev webpack-bundle-analyzer 时,npm 会解析该包的依赖树,并尝试安装它所依赖的所有子包

解决

使用 --legacy-peer-deps 忽略冲突依赖(适用于 Node.js v14+)