我正在尝试将以下库添加到react项目:
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
└─ [email protected]
info All dependencies
└─ [email protected]
✨ 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 <dependency>
时,所需的依赖项实际上已添加到package.json
,然后下载到node_modules
文件夹中。在这种情况下,您不必手动更新package.json
。您是否在项目的根文件夹中执行了yarn add
?这是必不可少的。