How to install a subdirectory as package?

(Cyril Auburtin) #1

I’d like to install a subdirectory of a git repo: https://github.com/caub/create-react-app/tree/eslint/packages/react-scripts

For example I’d like to do:

npm i -D github:caub/create-react-app/tree/eslint/packages/react-scripts#eslint
# or the equivalent:
npm i -D git+ssh://git@github.com/caub/create-react-app/tree/eslint/packages/react-scripts#eslint

It’s not working, but this is a git issue, not an npm issue

npm ERR!   fatal: remote error: 
npm ERR!      caub/create-react-app/tree/eslint/packages/react-scripts is not a valid repository name

I’ve seen: https://github.com/npm/npm/issues/2974#issuecomment-351118123 that suggests a feature like

npm i -D github:caub/create-react-app#eslint?path=packages/react-scripts

Does something like that already work? It’s necessary to have this feature

1 Like
(John Gee) #2

You can do this with npm packages, not sure about git links:

(Cyril Auburtin) #3

Thanks @shadowspawn, the package has this directory field set up: https://github.com/caub/create-react-app/blob/master/packages/react-scripts/package.json#L8

My question is how could I install it from its github link, not from npm? It’s a pending PR, not merged yet

1 Like