How to install an npm package from GitHub directly?

后端 未结 15 2061
失恋的感觉
失恋的感觉 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:18

    Update September 2016

    Installing from vanilla https github URLs now works:

    npm install https://github.com/fergiemcdowall/search-index.git
    

    EDIT 1: You can't do this for all modules because you are reading from a source control system, which may well contain invalid/uncompiled/buggy code. So to be clear (although it should go without saying): given that the code in the repo is in an npm-usable state, you can now quite happily install directly from github

    EDIT 2: (21-10-2019) We are now living through "peak Typescript/React/Babel", and therefore JavaScript compilation has become quite common. If you need to take compilation into account look into prepare. That said, NPM modules do not need to be compiled, and it is wise to assume that compilation is not the default, especially for older node modules (and possibly also for very new, bleeding-edge "ESNext"-y ones).

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

    Simple :

    npm install *GithubUrl*.git --save
    

    example :

    npm install https://github.com/visionmedia/express.git --save
    
    0 讨论(0)
  • 2020-11-22 07:20

    Because https://github.com/visionmedia/express is the URL of a web page and not an npm module. Use this flavor:

    git+https://github.com/visionmedia/express.git
    

    or this flavor if you need SSH:

    git+ssh://git@github.com/visionmedia/express.git
    
    0 讨论(0)
  • 2020-11-22 07:23

    Try this command

     npm install github:[Organisation]/[Repository]#[master/BranchName] -g
    

    this command worked for me.

     npm install github:BlessCSS/bless#3.x -g
    
    0 讨论(0)
  • 2020-11-22 07:27

    UPDATE now you can do: npm install git://github.com/foo/bar.git
    or in package.json:

    "dependencies": {
      "bar": "git://github.com/foo/bar.git"
    }
    
    0 讨论(0)
  • 2020-11-22 07:28

    You can also do npm install visionmedia/express to install from Github

    or

    npm install visionmedia/express#branch
    

    There is also support for installing directly from a Gist, Bitbucket, Gitlab, and a number of other specialized formats. Look at the npm install documentation for them all.

    0 讨论(0)
提交回复
热议问题