尝试从GitHub安装模块会导致以下错误:

package.json上的ENOENT错误。

容易复制使用express:

NPM安装https://github.com/visionmedia/express抛出错误。

NPM安装快速工程。

为什么我不能从GitHub安装?

下面是控制台输出:

npm http GET https://github.com/visionmedia/express.git
npm http 200 https://github.com/visionmedia/express.git
npm ERR! not a package /home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/tmp.tgz
npm ERR! Error: ENOENT, open '/home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/package/package.json'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Linux 3.8.0-23-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "https://github.com/visionmedia/express.git"
npm ERR! cwd /home/guym/dev_env/projects_GIT/proj/somename
npm ERR! node -v v0.10.10
npm ERR! npm -v 1.2.25
npm ERR! path /home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/package/package.json
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/guym/dev_env/projects_GIT/proj/somename/npm-debug.log
npm ERR! not ok code 0

当前回答

下面的一段代码为我安装从github存储库:

npm install git+ssh://<your_repository_ssh_clone_link>#<branch_name_if_any>

你可以得到ssh克隆链接如下:

所以对于上面的截图存储库,你可能需要像下面这样导入,

npm install git+ssh://git@github.com:Siddhu2/calculator-chatbot.git#master

master是我的分支,这是可选的,因为我只有一个分支。

其他回答

语法的一般形式是

<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]

也就是说你的案子会是这样吗

npm install git+ssh://git@github.com/visionmedia/express.git

来自npmjs文档:

npm install : Installs the package from the hosted git provider, cloning it with git. For a full git remote url, only that URL will be attempted. <protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:] is one of git, git+ssh, git+http, git+https, or git+file. If # is provided, it will be used to clone exactly that commit. If the commit-ish has the format #semver:, can be any valid semver range or exact version, and npm will look for any tags or refs matching that range in the remote repository, much as it would for a registry dependency. If neither # or semver: is specified, then master is used. If the repository makes use of submodules, those submodules will be cloned as well. If the package being installed contains a prepare script, its dependencies and devDependencies will be installed, and the prepare script will be run, before the package is packaged and installed. The following git environment variables are recognized by npm and will be added to the environment when running git: GIT_ASKPASS GIT_EXEC_PATH GIT_PROXY_COMMAND GIT_SSH GIT_SSH_COMMAND GIT_SSL_CAINFO GIT_SSL_NO_VERIFY See the git man page for details. Examples: npm install git+ssh://git@github.com:npm/npm.git#v1.0.27 npm install git+ssh://git@github.com:npm/npm#semver:^5.0 npm install git+https://isaacs@github.com/npm/npm.git npm install git://github.com/npm/npm.git#v1.0.27 GIT_SSH_COMMAND='ssh -i ~/.ssh/custom_ident' npm install git+ssh://git@github.com:npm/npm.git npm install

因为https://github.com/visionmedia/express是一个网页的URL,而不是一个npm模块。使用这种风格:git+{url}.git

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

或者如果你需要SSH:

git+ssh://git@github.com/visionmedia/express.git

或者如果你需要安装一个GitHub企业存储库:

git+https://<github enterprise url>/<org>/<repo>.git#<branch>

从GitHub安装,你也可以这样做

npm install visionmedia/express

Or

npm install visionmedia/express#branch

也支持直接从Gist, Bitbucket, GitLab和其他一些专门的格式安装。看看npm的安装文档。

如果Git没有安装,我们可以尝试:

npm install --save https://github.com/Amitesh/gulp-rev-all/tarball/master

截至2016年9月,从普通HTTPS GitHub url安装现在可以工作:

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

你不能对所有的模块都这样做,因为你正在从一个源代码控制系统中读取,它很可能包含无效的/未编译的/有bug的代码。所以需要明确的是(尽管这应该是不言而喻的):鉴于存储库中的代码处于npm可用状态,您现在可以非常愉快地直接从GitHub安装。

2019年10月,我们正经历着“TypeScript/React/Babel峰值”,因此JavaScript编译已经变得相当普遍。如果需要考虑编译,请查看prepare。也就是说,NPM模块不需要编译,并且明智的假设编译不是默认的,特别是对于较旧的节点模块(可能也适用于非常新的、前沿的“ESNext”-y模块)。