如何从github导入带有作用域名称的npm模块?

时间:2015-09-30 15:50:07

标签: node.js npm javascript

我试图用npm安装一个github项目的fork(在master而不是任何特定的提交,因为我想针对它开发):

% npm install parkan/graffiti-mongoose
@risingstack/graffiti-mongoose@2.0.0 node_modules/@risingstack/graffiti-mongoose

这似乎是查找父回购并在我的gh上安装版本对主版本,到目前为止一切顺利。请注意,该软件包使用scoped package name semantics,我认为这是问题的一部分。

% npm list |grep mongoose
├── @risingstack/graffiti-mongoose@2.0.0 (git://github.com/parkan/graffiti-mongoose.git#01a8480fa7d787a4d74bf3bcb257d01b4d73129a)
% ls node_modules/@risingstack/graffiti-mongoose
CHANGELOG.md    LICENSE     fixture
CONTRIBUTING.md README.md   package.json

但是,我无法以任何明显的方式导入节点或要求它:

> require('graffiti-mongoose');
Error: Cannot find module 'graffiti-mongoose'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at repl:3:1
    at Object.exports.runInThisContext (vm.js:54:17)
    at _eval (/usr/local/lib/node_modules/babel/lib/_babel-node.js:86:26)
    at REPLServer.replEval (/usr/local/lib/node_modules/babel/lib/_babel-node.js:169:14)
    at bound (domain.js:250:14)
    at REPLServer.runBound [as eval] (domain.js:263:12)
> require('@risingstack/graffiti-mongoose');
Error: Cannot find module '@risingstack/graffiti-mongoose'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at repl:3:1
    at Object.exports.runInThisContext (vm.js:54:17)
    at _eval (/usr/local/lib/node_modules/babel/lib/_babel-node.js:86:26)
    at REPLServer.replEval (/usr/local/lib/node_modules/babel/lib/_babel-node.js:169:14)
    at bound (domain.js:250:14)
    at REPLServer.runBound [as eval] (domain.js:263:12)
> require('risingstack/graffiti-mongoose');
Error: Cannot find module 'risingstack/graffiti-mongoose'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at repl:3:1
    at Object.exports.runInThisContext (vm.js:54:17)
    at _eval (/usr/local/lib/node_modules/babel/lib/_babel-node.js:86:26)
    at REPLServer.replEval (/usr/local/lib/node_modules/babel/lib/_babel-node.js:169:14)
    at bound (domain.js:250:14)
    at REPLServer.runBound [as eval] (domain.js:263:12)

如何在这样的子目录中包含一个包?

2 个答案:

答案 0 :(得分:1)

这似乎是npm中的错误。检出repo并从本地文件系统安装工作正常。

提交的问题:https://github.com/npm/npm/issues/9798

编辑:这似乎是在没有检查工件且必须在模块可用之前运行预发布脚本的情况下从github安装的限制,请参阅https://github.com/npm/npm/issues/3055

答案 1 :(得分:0)

我已添加到我的package.json:

    "some_github_package": "git+https://github.com/user_name/package_name.git",

然后运行npm install,你就会得到它