Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/[email protected] 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/[email protected] (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?

like image 657
Arkadiy Kukarkin Avatar asked Nov 21 '22 04:11

Arkadiy Kukarkin


1 Answers

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

like image 66
Arkadiy Kukarkin Avatar answered Nov 23 '22 19:11

Arkadiy Kukarkin