如何通过 Yarn 安装带有本地路径的包?找不到包 [英] How to install package with local path by Yarn? It couldn't find package
问题描述
在我的 package.json
中,我通过其相对路径指向本地包 my-custom-i18n
:
In my package.json
I'm pointing local package my-custom-i18n
by its relative path:
"dependencies": {
"core-js": "^2.4.1",
"my-custom-i18n": "./../MyProject.Shared/myproject-i18n",
"rxjs": "5.0.0-beta.12",
...
}
npm install
正确安装包,但 yarn
有问题,根本找不到这个包:
npm install
installs packages correctly, but yarn
has problem with it and simply cannot find this package:
$ yarn
yarn install v0.15.1
info No lockfile found.
[1/4] Resolving packages...
error Couldn't find package "myproject-i18n" on the "npm" registry.
info Visit http://yarnpkg.com/en/docs/cli/install for documentation about this command.
我看到它在 npm
注册表中查找,此包不在该注册表中.
I see that it looks it on the npm
registry, where this package doesn't live.
在本地包中使用 yarn 有什么变化吗?本地包是指由相对路径指向的包为 my-custom-i18n
.
Is there any change to use yarn with local packages?
By local packages I mean packages pointed by relative path as my-custom-i18n
.
推荐答案
对于yarn版本<2.x
Yarn 需要前缀 file:
用于本地包.
对于相对路径:
yarn add file:./../your-project
对于绝对路径
yarn add file:/dev/your-project
对于您的示例,package.json
中的依赖项将声明如下:
For your example, dependency in package.json
would be declared as follows:
"my-custom-i18n": "file:./../MyProject.Shared/myproject-i18n",
这也适用于 Yarn 和 NPM.
This works both for Yarn and NPM as well.
它与 NPM 客户端不兼容,Yarn 团队意识到并声明支持此行为 - 参考GitHub 问题.
It is incompatibility with NPM client, Yarn team is aware and declared to support this behavior - reference on GitHub issue.
更新:
自 v0.21.0 发布以来,不需要 file:
前缀.参见 pull-request with fix 和 更改日志.
Since v0.21.0 release, file:
prefix is not needed.
See pull-request with fix and changelog.
这篇关于如何通过 Yarn 安装带有本地路径的包?找不到包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!