How to install package with local path by Yarn? It couldn't find package

点点圈 提交于 2019-11-28 16:22:39

问题


In my package.json I'm pointing local package my-custom-i18n by its relative path:

package.json

"dependencies": {
 "core-js": "^2.4.1",
 "my-custom-i18n": "./../MyProject.Shared/myproject-i18n",
 "rxjs": "5.0.0-beta.12",
 ...
}

npm install installs packages correctly, but yarn has problem with it and simply cannot find this package:

yarn output

$ 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.

I see that it looks it on the npm registry, where this package doesn't live.

Question

Is there any change to use yarn with local packages? By local packages I mean packages pointed by relative path as my-custom-i18n.


回答1:


Yarn requires prefix file: for local packages.

For relative path:

yarn add file:./../your-project

For absolute path

yarn add file:/dev/your-project

For your example, dependency in package.json would be declared as follows:

 "my-custom-i18n": "file:./../MyProject.Shared/myproject-i18n",

This works both for Yarn and NPM as well.

It is incompatibility with NPM client, Yarn team is aware and declared to support this behavior - reference on GitHub issue.

Update:

Since v0.21.0 release, file: prefix is not needed. See pull-request with fix and changelog.



来源:https://stackoverflow.com/questions/40102686/how-to-install-package-with-local-path-by-yarn-it-couldnt-find-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!