How to install an npm package from GitHub directly?

后端 未结 15 2042
失恋的感觉
失恋的感觉 2020-11-22 06:48

Trying to install modules from github results in:

ENOENT error on package.json.

Easily reproduced using express:

15条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 07:31

    The methods are covered pretty well now in npm's install documentation as well as the numerous other answers here.

    npm install git+ssh://git@github.com:/]
    npm install git+ssh://git@github.com:/[#semver:^x.x]
    npm install git+https://git@github.com//
    npm install git://github.com//
    npm install github:/[#]
    

    However, something notable that has changed recently is npm adding the prepare script to replace the prepublish script. This fixes a longstanding problem where modules installed via git did not run the prepublish script and thus did not complete the build steps that occur when a module is published to the npm registry. See https://github.com/npm/npm/issues/3055.

    Of course, the module authors will need to update their package.json to use the new prepare directive for this to start working.

提交回复
热议问题