LoginSignup
5
2

More than 1 year has passed since last update.

githubリポジトリのサブフォルダーからnpm installしたい時

Last updated at Posted at 2022-05-30

概要

github上で以下のような構成のリポジトリがあるとする。
ディレクトリ直下ではなく、サブフォルダにいくつかのpackageがまとまっているmonorepoだ。

.github/
packages/
├ package-a
│ └ package.json # <- これをインストールしたい
└ package-b
   └ package.json

サブフォルダ内のあるpackage(例えばpackage-a)をインストールしたい時、単に npm i https://github.com/<user>/<repo>/packages/package-a とするだけではインストールできない。

npm i https://github.com/<user>/<repo>/packages/package-a

npm ERR! code E404
npm ERR! 404 Not Found - GET https://github.com/<user>/<repo>/packages/package-a
npm ERR! 404
npm ERR! 404  'https://github.com/<user>/<repo>/packages/package-a' is not in this registry.
npm ERR! 404 This package name is not valid, because
npm ERR! 404  1. name can only contain URL-friendly characters
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

対処法

そんな時はgitpkg.now.shを使おう。
サブフォルダからのインストールを簡単にしてくれるツールだ。

 Using sub folders of a repo as yarn/npm dependencies made easy

使い方は github.com を gitpkg.now.sh に置き換えるだけだ。

npm i https://gitpkg.now.sh/<user/<repo>/packages/package-a?<commit>
5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2