10

I am trying to bundle up my app with browserify and am getting this error:
Cannot find module 'jquery' from '/home/test/node_modules/backbone'

Now questions of this nature have been asked before, but the solutions haven't helped me. Perhaps I have somewhat of a unique case.

In another app, running npm install jquery fixed it. I didn't have it in my package.json and I wasn't requiring jquery in any of my files like what's done here. Everything worked.

In this new app, it doesn't. I tried reinstalling jquery with npm. Nothing. Added it to my dependencies in package.json. Nothing. Included it in my code:

$ = require('jquery'); Backbone.$ = $;

Nothing.

Does anyone have experience with this? What could be going wrong?

Edit:

Diff'd the package.json of the jquery module in the working app and the current one.

Working one:

 "url": "https://github.com/jquery/jquery.git"
 "_from": "jquery@*"

Broken one:

 "url": "git+https://github.com/jquery/jquery.git"
 "_from": "jquery@>=2.1.0 <3.0.0"
 "readme": "ERROR: No README data found!"

If you want more context (line numbers, parent property, and such), I'd be happy to provide that. I just wanted to simplify it - maybe something stands out.

Edit 2:

Changing the "url" param shouldn't changed anything. Replacing the "_from" with the one that works didn't change anything.

Now, I'm wondering why README data is not found. My README files are the same. Granted, I highly doubt that this is the source of the problem.

Edit 3:

My solution was to remove the jquery module and just include jquery.js in my index view. I'm not particularly happy with this, but it works.

I would still like an answer though; curious what was wrong before.

5
  • 1
    I ran into the same error when I was using npm link to symlink a dependency that I was developing outside of npm. Sounds different than your situation though. Commented Sep 30, 2015 at 18:55
  • I ran into this too... Was your symlink dependency requiring Backbone which was requiring jQuery? npm install jquery from the symlink dep fixed the problem... but I would also setup the browserify shim in the dep folder rather than the parent proejct. Commented Oct 5, 2015 at 18:33
  • @ilovett Thanks for your help. Unfortunately this was a project I was working on during the summer and don't have access to my code anymore. I don't understand what exactly a symlink dependency is, but Backbone (or its Views at least) do require JQuery. Commented Oct 5, 2015 at 21:37
  • @Pushkin Backbone requires jQuery for ajax calls as well. Commented Oct 18, 2015 at 19:58
  • rkulla.blogspot.com/2014/04/… Commented Jun 14, 2016 at 11:59

1 Answer 1

2

This should work well with npm install --save jquery. Seems that browserify searches for jquery module in backbone location. Can you find out why is this so ? Don't you have some browserify-shim configuration errors in your package.json ?

If you still have problem you can use browserify-shim to point browserify to proper location by putting this in package.json

  "browserify": {
    "transform": [
      "browserify-shim"
    ]
  },
  "browser": {
    "jquery": "./node_modules/yet/old/jquery/location"
  }
Sign up to request clarification or add additional context in comments.

1 Comment

I am no longer working on this project, so I cannot answer your questions nor test your solution. Thanks anyway

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.