How to install an npm package from GitHub directly?

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

Trying to install modules from github results in:

ENOENT error on package.json.

Easily reproduced using express:

相关标签:
15条回答
  • 2020-11-22 07:30

    The current top answer by Peter Lyons is not relevant with recent NPM versions. For example, using the same command that was criticized in this answer is now fine.

    $ npm install https://github.com/visionmedia/express
    

    If you have continued problems it might be a problem with whatever package you were using.

    0 讨论(0)
  • 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:<githubname>/<githubrepo.git[#<commit-ish>]
    npm install git+ssh://git@github.com:<githubname>/<githubrepo.git>[#semver:^x.x]
    npm install git+https://git@github.com/<githubname>/<githubrepo.git>
    npm install git://github.com/<githubname>/<githubrepo.git>
    npm install github:<githubname>/<githubrepo>[#<commit-ish>]
    

    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.

    0 讨论(0)
  • 2020-11-22 07:31

    I tried npm install git+https://github.com/visionmedia/express but that took way too long and I wasn't sure that would work.

    What did work for me was - yarn add git+https://github.com/visionmedia/express.

    0 讨论(0)
  • 2020-11-22 07:32

    Install it directly:

    npm install visionmedia/express
    

    Alternatively, you can add "express": "github:visionmedia/express" to the "dependencies" section of package.json file, then run:

    npm install
    
    0 讨论(0)
  • 2020-11-22 07:37

    You could also do

    npm i alex-cory/fasthacks
    

    or

    npm i github:alex-cory/fasthacks
    

    Basically:

    npm i user_or_org/repo_name
    
    0 讨论(0)
  • 2020-11-22 07:38

    If git is not installed, we can try

    npm install --save https://github.com/Amitesh/gulp-rev-all/tarball/master
    
    0 讨论(0)
提交回复
热议问题