Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken with new npm 0.3.9 #18

Closed
zefhemel opened this issue Mar 1, 2011 · 10 comments
Closed

Broken with new npm 0.3.9 #18

zefhemel opened this issue Mar 1, 2011 · 10 comments

Comments

@zefhemel
Copy link

zefhemel commented Mar 1, 2011

When I install nStore with npm it seems to install fine. However, when I require('nstore'), node tells me the module cannot be found.

@creationix
Copy link
Owner

Yep, npm dropped support for the modules hash. The irony is I switched to it a while back because Isaac said it was the most future proof. I'm actually not sure how to preserve the require('nstore/pluginX') style modules in the new npm. Care to submit a patch for package.json?

@zefhemel
Copy link
Author

zefhemel commented Mar 1, 2011

I had the same problem with persistence.js, also wasn't able to preserve the require('.../...') style there either.

Tried to patch it with:

"main": "lib/nstore.js",

But then there seem to be other problems. It says it cannot find the pattern library, which, in turn probably has the same problem.

@subpop
Copy link

subpop commented Mar 8, 2011

Bleh. This deprecation really requires modules to have a significant amount of code change made to the way they export. If you add:

"directories": {
    "lib": "./lib",
}

to your package.json, you can then access the individual files as such:

var Queue = require('pattern/lib/pattern/queue');

But I think to properly fix this, you have to rewrite pattern in such a way that you can access the submodules like Hash and Queue through the top-level object. Something like:

var pattern = require('pattern');
var hash = pattern.hash;
var queue = pattern.queue;

And inside the pattern module's index.js, you configure your object to export hash and queue. Make sense?

@creationix
Copy link
Owner

Yeah, that's what I usually do. See https://github.com/creationix/creationix/blob/master/index.js for an example. I don't have time to do this right now, but I'll take a pull request.

@subpop
Copy link

subpop commented Mar 8, 2011

Awesome. I'll fork & try patching this in tonight.

@creationix
Copy link
Owner

Hmm, I wonder if this is a good idea for pattern since the root object it the parent prototype for everything. Then all objects created would have properties stuck no them which is not good. We might need to re-think how the whole thing is structured.

@subpop
Copy link

subpop commented Mar 8, 2011

It almost feels like with this new structure, you can't export multiple root objects. Hash, Queue and Pattern all have to become independently distributed & require()'d modules. That's what I mean about code changes being required. The way Pattern is written, yea, it almost requires a re-engineering.

Maybe Hash becomes PatternHash?

Or pattern (the root-level-object) becomes a creator for the 3 child objects. Something like:

var PatternGenerator = require('pattern'); // Is a singleton class, to be compatible with npm 0.3.9+
var Hash = PatternGenerator.create('hash'); // Creates a Hash object
var Queue = PatternGenerator.create('queue'); // Creates a Queue object
var Pattern = PatternGenerator.create('pattern'); // or maybe Pattern.create()?

@Pita
Copy link
Contributor

Pita commented Apr 10, 2011

I have the same problem :/ Is there any solution avaiable?

@sudr
Copy link

sudr commented May 13, 2011

Any solutions / workarounds. I'm a node.js/nbm noob. So I'd appreciate some detail on the workarounds.

@creationix
Copy link
Owner

Fixed now. I had to refactor pattern and nstore to be friendly to the new npm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants