简体   繁体   中英

How to import npm module with scoped name installed from github?

I'm trying to install a fork of a github project with npm (at master rather than any specific commit since I want to develop against it):

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

This appears to look up the parent repo and install it versioned against master on my gh, so far so good. Note that the package uses scoped package name semantics , which I think is a part of the problem.

% 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

However, I can't get node to import or require it in any obvious way:

> 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)

How do I require a package that's inside a subdirectory like this?

This appears to be a bug in npm. Checking out the repo and installing from local filesystem works fine.

Issue filed: https://github.com/npm/npm/issues/9798

EDIT: this appears to be a limitation of installing from github in cases where artifacts aren't checked in and a prepublish script must run before the module is usable, see https://github.com/npm/npm/issues/3055

I added to my package.json:

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

Then run npm install and you'll get it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM