Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 475
michalczukm Avatar asked Oct 18 '16 07:10

michalczukm


People also ask

Can you install any NPM package with yarn?

Yarn can consume the same package. json format as npm, and can install any package from the npm registry. This will lay out your node_modules folder using Yarn's resolution algorithm that is compatible with the node. js module resolution algorithm.

How do I install all packages in a package json with yarn?

Installing Options Installing all dependencies: yarn or yarn install. Installing one and only one version of a package: yarn install --flat. Forcing a re-download of all packages: yarn install --force.

How do I force an NPM package to install?

Run npm update -g npm. Execute this command by running the command prompt as Administrator npm install -g windows-build-tools. Run npm install inside the project folder where the package. json file is located, if it doesn't work run: npm install --force.


1 Answers

For yarn version < 2.x

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.

like image 117
Piotr Lewandowski Avatar answered Sep 27 '22 21:09

Piotr Lewandowski