【问题标题】:Installed a package through npm, get 'This dependency was not found:' error通过 npm 安装包,得到 'This dependency was not found:' 错误
【发布时间】:2020-09-04 01:17:27
【问题描述】:

我在我的 vue 项目中通过 npm install 命令安装了一个名为 htmldiff 的包。 然后我尝试在一个组件中导入包

import { diff } from 'htmldiff'; // the package didn't use default export

我得到了这个错误。

This dependency was not found:

* htmldiff in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Editor3.vue?vue&type=script&lang=js&

To install it, you can run: npm install --save htmldiff

我可以在项目的 package.json 文件中看到 htmldiff。 我还可以看到在 htmldiff 的 package.json 中指定了主文件,如下所示:

"main": "htmldiff.js",

我还应该看什么?

【问题讨论】:

  • 你试过用npm cache clean删除缓存吗?

标签: javascript vue.js npm npm-install


【解决方案1】:

包有问题。

/node_modules/htmldiff/package.json 中,main 定义为htmldiff.js,但该文件实际上并不存在。它需要是main: "src/htmldiff.js"

【讨论】:

  • 哦,我忽略了路径,添加准确的路径解决了问题。谢谢。
  • 请考虑在 github 上为包打开一个问题。通常它应该开箱即用,并且 .js 也应该被缩小!
猜你喜欢
  • 2016-10-29
  • 1970-01-01
  • 2022-09-25
  • 2012-03-25
  • 1970-01-01
  • 2018-11-05
  • 2022-08-14
  • 2018-04-17
  • 1970-01-01
相关资源
最近更新 更多