Please set back jQuery to dependencies in package.json #535

Closed
Meettya opened this Issue Mar 24, 2013 · 14 comments

Projects

None yet

7 participants

@Meettya

Hi!

I dont know, why it should be done, but its bad idea.

From now backbone.marionette can`t be used as ComonJS module anymore, because node.js require will fail require() it. Thats it work - node search for fist (deep to shallow direction) node_modules dir and than search any modules in that dir, but if absent - throw error.

Please, return jQuery to dependencies.

@derickbailey
Marionette.js member

What errors are you getting, when? On install, or when trying to require('backbone.marionette');?

@Meettya

So, if we are do this -

$ cd /tmp
$ mkdit marionette_test
$ cd ./marionette_test
$ npm install backbone.marionette

in install log we see

backbone.marionette@1.0.1 node_modules/backbone.marionette
├── backbone@1.0.0 (underscore@1.4.4)
├── backbone.wreqr@0.2.0 (backbone@0.9.10, jquery@1.8.3)
└── backbone.babysitter@0.0.5 (backbone@0.9.10, jquery@1.8.3)

next, do
$ echo 'var marionette = require ("backbone.marionette");' > index.js
and
$ node ./index.js

as result

module.js:340
    throw err;
          ^
Error: Cannot find module 'underscore'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Marionette (/private/tmp/test6/node_modules/backbone.marionette/lib/core/amd/backbone.marionette.js:4:22)
    at Object.<anonymous> (/private/tmp/test6/node_modules/backbone.marionette/lib/core/amd/backbone.marionette.js:16:2)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

because, as I said, node get closest 'node_modules' dir and search there, than throw error.

So, to have possibility to require() module all it dependencies SHOULD be at closest 'node_modules' dir, or it will be broken for node.

if we do
$ npm install underscore
and then repeat
$ node ./index.js
all be worked like a charm

but correct behavior must be
$ cd ./node_modules/backbone.marionette/
$ npm install underscore
because any module should have own dependencies in it own 'node_modules' dir, as node.js teach as.

PS. Why I need have possibility to require() Marionette in node?
I write my code in CommonJS style, with require(), module.exports and mocha auto-test and other things, when pack it in little bundles with my own bicycle named Clinch (like browserify, but it hasn't fatal flaw :) ) and send it to client. And now its not working :(.

@cobbweb
Marionette.js member

If you want to make a Marionette.Application in node you have to jump through a few hoops:

npm install backbone backbone.marionette backbone.wreqr jquery underscore

Then in your script

var Backbone = require('backbone');
var Marionette = require('backbone.marionette');
Marionette.$ = Backbone.$ = require('jquery');
Backbone.Wreqr = require('backbone.wreqr');

var MyApp = new Marionette.Application();

This fixes the missing underscore dependency, and manually adds jQuery and Wreqr onto Backbone because the way it's done in Marionette+Node doesn't work.

@Meettya

Aha. I see, ok, I try it, thanx for answer in details.

But, at last, I still want to point to npm package idea. Package itself its thing, that include inside all its dependencies - as I see npm solve two problems - hold dependencies together and prevent "dll hell".

Second one solved by using different node_modules dir for each npm package.

Its important conventions, and I cant see why Backbone.Marionette not hold it in. Is it any kind of profit exist? What problems will resolved?

@greghart

Thanks 'cobbweb' for that quick fix. +1 on the issue also, dependencies should be declared within package.json and allow us to out of the box require 'backbone.marionette', current setup outlined above is much more fragile.

@cobbweb
Marionette.js member

Any word on why jQuery was removed?

@cobbweb cobbweb was assigned Jan 14, 2014
@cobbweb
Marionette.js member

I'm thinking we should add jQuery back as a dependency. Looks there is a CommonJS version.

Underscore is CommonJS compliant too, so might add that as well?

Any objections @samccone?

@samccone
Marionette.js member

nope none at all 🔑

@rhubarbselleven

Is jQuery really a dependency?

@cobbweb
Marionette.js member

Yes. Or do you just mean something jQuery-like?

@rhubarbselleven

But in that case, isn't it relying on Backbones jQuery dependency?

@cobbweb
Marionette.js member

Hmm I see what you're saying, let me think about it.

@jmeas
Marionette.js member

I agree with @rhubarbselleven. It's not explicitly used in the CommonJS/AMD build, either.

@samccone
Marionette.js member
@samccone samccone closed this Mar 3, 2014
@bufke bufke added a commit to bufke/guides that referenced this issue Dec 17, 2015
@bufke bufke Update installing_marionette.md
Two fixes so that these steps can be followed without error.

1. Jquery must be explicitly installed. See discussion [here](marionettejs/backbone.marionette#535)
2. require needs to use `./` to refer to a file that is in the same folder. Otherwise it will search in node_modules.
12ca058
@bufke bufke referenced this issue in marionettejs/guides Dec 17, 2015
Merged

Update installing_marionette.md #2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment