Comments (8)
this is the same issue that was discussed in browserify/wzrd.in#73
https://github.com/KoryNunn/gaffa-textbox/blob/master/package.json#L18-L20 should be a dependency
and not a peerDependency
. If a module does require('foo')
then foo
must be in the dependency
section of package.json
from requirebin.
This is incorrect.
http://blog.nodejs.org/2013/02/07/peer-dependencies/
peerDependencies are dependencies that are required for the module to run, but should not be installed as a result of/in the node_modules folder of the module. They are often used for 'plugins' (or in this example, the gaffa-textbox module needs whatever gaffa module you are using in your project.)
requirebin should be able to run anything that is a valid node project, that depends on modules on NPM.
from requirebin.
that description is correct, the incorrect part is in that you are doing require('gaffa')
here https://github.com/KoryNunn/gaffa-textbox/blob/master/textbox.js#L1
since it's a peerDependency
in that module you can't require()
it in that module, you have to require it somewhere else and pass it in
from requirebin.
here's the discussion me and @anvaka had yesterday in IRC
21:01 < ogd> jesusabdullah: npm will only install things in the dependencies field. if your module does require('something') then 'something' *has* to be in the dependencies field. peerDependencies aren't meant to be used for things that you require() inside your module
21:02 < jesusabdullah> It's been a while
21:02 < jesusabdullah> but yeah
21:02 < jesusabdullah> cool
21:03 < anvaka> ogd: so, peer dependencies are evil?
21:05 < ogd> anvaka: kind of... we used them in voxel.js optimistically but they caused more issues than they solved
21:06 < anvaka> ogd: interesting...
21:06 < anvaka> Why do they exist then :)?
21:06 < ogd> i think theyre intended for a sort of plugin case
21:07 < ogd> e.g. module A doesn't require module B but rather an instance of B gets passed into A at runtime
21:07 < ogd> and A needs to specify which version of B it's compatible with
21:07 < ogd> e.g. a jquery plugin
21:07 < anvaka> That's exactly the use case of https://github.com/jesusabdullah/browserify-cdn/issues/73
21:07 < anvaka> :)
21:08 < ogd> right but https://github.com/anvaka/typeahead.an/blob/master/index.js#L4
21:08 < ogd> since you are doing require('an') then it isn t a peer dep, its just a normal dep
21:08 < ogd> peer dep would be for a situation where you require('an') in some higher level app and pass it into typeahead.an
21:08 < anvaka> Hmm but that's how I register a plugin
21:09 < anvaka> Oh
21:09 < ogd> similar to how jquery plugins all attach themselves to a single instance of $
21:09 < anvaka> got it
...
21:19 < anvaka> I'm just not sure how to create a singleton in node :)
21:20 < anvaka> Which is shared across all major package versions
21:20 < anvaka> s/across/within/
21:21 < anvaka> Doh I'm terrible at explaining myself :)
21:22 < anvaka> What I meant: I want to have same instance of an object for all versions of package Foo v 0.1.x
21:23 < ogd> anvaka: hmm i dont think you can do that with require()
21:23 < ogd> anvaka: you have to require it once and then either pass it around or set it as a global
21:23 < anvaka> With peer dependencies you can, right?
21:24 < ogd> anvaka: peer dependencies doesn't change the way require() works
21:25 < anvaka> ogd: here: https://github.com/anvaka/an/blob/master/lib/directive.js
21:25 < rch> i guess you could make a module which would at require-time initialize a module-scoped singleton and then have all those packages require() that module to share the singleton… feels like a problem you shouldn't have to solve
21:25 < anvaka> I expose an API and I hope to have same version of `an`
21:29 < anvaka> rch: that's what module `an` is doing
21:29 < anvaka> Hmmm
21:30 < anvaka> So if I just make an as a regular dependency can I guarantee to have same version of an?
21:30 < anvaka> That seems like a super silly question :)
21:31 < anvaka> I guess I can just put correct semver and it all will work
21:31 < anvaka> Doh :). Thank you guys!
from requirebin.
This seems like an underutilization of the module system.
- For starters, this works in a normal project.
- It isn't "dirty", as you specify up front what packages are needed for the module to work, but that they should be required elsewhere. It is totally clear what is intended.
- Passing the peerDependency in for every module that needs it is a huge amount of pointless code.
I understand that peerDependencies + require() don't exactly fit the usual programming style of node, but in some cases, it makes a lot of sense.
The most critical point there is that this does work in a normal environment, so even if it isn't 'correct' (which seems more opinion than anything), this makes requirebin not functionally in parity with node.
from requirebin.
I see where you are coming from, but this module is currently broken https://github.com/KoryNunn/gaffa-textbox, because doing npm install
doesn't install the dependencies (meaning in this case gaffa
doesn't get installed), which is the entire point of doing npm install
in the first place.
It's not my opinion, I'm just explaining how NPM and browserify work. You're trying to publish a module that doesn't declare all of it's dependencies correctly (correctly here means "the way NPM wants you to" which means "put all the things you require()
in dependencies
"), and the error you get on requirebin is because NPM works differently then how you are expecting here.
from requirebin.
Why then, if I create that exact project locally (with associated package.json), run npm install, and then browserify, does it work?
It would be incorrect for gaffa-textbox to install gaffa during an npm install.
it would be silly to pass gaffa into 50-60 modules in a project, especially when you currently don't need to.
There seems to be no hard and fast 'this is wrong' anywhere in the documentation for npm, or node.
This is now a debate of opinion, because this does work with npm+browserify, so now the question is, does requirebin intend to work like any normal local install of npm+browserify, or will it work differently.
As a related side note, which of these two options do you think is cleaner?
https://gist.github.com/KoryNunn/9881655
They both work, and you can't accidentally not install the right modules in either case.
from requirebin.
I'm not going to discuss this further as this isn't a use case I'm willing to spend any more time and effort supporting. This isn't even an issue with requirebin, it's an issue with browserify-cdn, or perhaps even browserify or NPM. Please take the discussion elsewhere.
from requirebin.
Related Issues (20)
- Can't install browserify-cdn
- Receiving errors when trying to run promises-tests
- Can't require browserify... HOT 2
- Flagrant system error
- iframe has scrolling="no" HOT 2
- <script> & <link> tags are ignored (possible solution included)
- es6 destructuring and indentation HOT 1
- CORS error when I try to require
- Debug mode
- Can't save from gist HOT 4
- Where are the libraries loaded and where does the execution take place?
- Need to refresh once after visiting site in Chrome HOT 3
- cannot read property content of undefined HOT 1
- Error: CORS request rejected: https://wzrd.in/multi HOT 4
- gatekeeper.maxogden.com not resolving HOT 2
- HTTPS support HOT 1
- ** operator not allowed HOT 1
- Clean page logs errors in console: `sinon is not defined`
- Current project status HOT 1
- Is requirebin.com still in use HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from requirebin.