javascript - 如何添加依赖来响应?
问题描述
我正在尝试将以下库添加到反应项目中:
https://github.com/rndme/download
我做了以下事情:
yarn add https://github.com/rndme/download
并得到了这样的回应:
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ downloadjs@1.4.8
info All dependencies
└─ downloadjs@1.4.8
✨ Done in 2.19s.
然后我更新了 package.json 以包含它:
"dependencies": {
"bootstrap": "4.1.3",
"react": "^16.6.0",
"react-cookie": "3.0.4",
"react-dom": "^16.6.0",
"react-router-dom": "4.3.1",
"react-scripts": "2.1.0",
"reactstrap": "6.5.0",
"downloadjs": "1.4.8"
},
并添加了一些代码来调用它:
async downloadFile(file, url) {
const res = await fetch(url);
const blob = res.blob();
// from downloadjs it will download your file
download(blob, file, "text/plain");
}
但是,它不会编译:
Failed to compile
./src/LicenseList.js
Line 64: 'download' is not defined no-undef
知道为什么吗?
解决方案
如果您使用纱线,您只需要编写yarn add mydepencyname
或yarn add -D mydependencyname
添加 devDependency (也就是说“仅在开发阶段有用”。
您将在 npm.com 上找到正确的依赖项名称。要更新依赖项,只需键入yarn upgrade-interactive --latest
,然后按空格键选择要更新的包。
推荐阅读
- android - 你可以配置 Android Room 来生成 Kotlin 代码而不是 Java
- pdf - Tableau 将 PDF 插入仪表板
- python - 如果单元格中存在值,则获取列名
- c# - 如何从 Azure 云应用服务获取用户 IP
- java - Swagger:为 java.util.Map 设置 @ApiModelProperty#datatype 的类型定义
- python - Pyspark:如何将数据帧拆分为块并保存它们?
- javascript - JavaScript 中的冒泡排序算法
- javascript - 从 const 值调用函数
- java - 在双精度内返回特定单位(作为整数)的更有效方法?
- string - SwiftUI:如何将 Double 与 String 组合并进行数学计算?