Yarn: add dependency from subdirectory in git repository

Viewed 3255

I use yarn in my React Native project. I would like to add a fork of jest-enzyme package to my dependencies (the fork adds Flow type definitions).

The problem is that the package I need is not in the root of repository but in packages/jest-enzyme subdirectory.

Running yarn add --dev https://github.com/lifeiscontent/enzyme-matchers.git installs the whole enzyme-assertions package.

If I try to import it as import 'enzyme-assertions/jest-enzyme';, I get "Cannot find module" error. import 'jest-enzyme'; does not work either (same error).

I also tried running yarn add --dev https://github.com/lifeiscontent/enzyme-matchers.git/packages/jest-enzyme, but this is not supported (I am getting 404 error). # is for branches, commits and tags, so I don't think it will work.

So how do I install this package?

2 Answers

Try https://gitpkg.now.sh/

yarn add https://gitpkg.now.sh/<user>/<repo>/<subdir>[?<branch>]

For this question:

yarn add https://gitpkg.now.sh/enzyme-matchers/packages/jest-enzyme
Related