Fabio B.
Fabio B.

Reputation: 9400

jquery module not found by grunt-browserify

My app configuration includes:

package.json

{
  "name": "myapp",
  "version": "0.0.1",
  "scripts": {
    "start": "node app"
  },
  "repository": {
    "type": "git",
    "url": "[email protected]:me/myapp"
  },
  "dependencies": {
    "browserify": "^5.10.1",
    "browserify-shim": "^3.7.0",
    "grunt-browserify": "^2.1.4",
  },
  "engines": {
    "node": "0.10.x"
  },
  "browser": {
    "jquery": "public/bower_components/jquery/dist/jquery.min.js"
  },
  "browserify-shim": {
    "jquery": { "exports": "$" }
  },
  "browserify": {
    "transform": [
      "browserify-shim"
    ]
  }
}

Gruntfile.js

module.exports = function(grunt) {
    grunt.initConfig({
        browserify: {
            app: {
                src: [ 'public/javascripts/app.js' ],
                dest: 'public/javascripts/build.js'
            }
        }
    });

    grunt.loadNpmTasks('grunt-browserify');
    grunt.registerTask('default', ['browserify']);
};

public/javascripts/app.js

var $ = require('jquery');

$(document).ready(function() {
    alert('Ciao!');
});

Result is:

Running "browserify:app" (browserify) task Error: module "jquery" not found from "/Users/me/GitHub/myapp/public/javascripts/app.js"

I found similar configuration examples online, I can't find my error, please help me! I just want to use grunt and browserify together in my project. Next step will be including twitter bootstrap.

BTW, I don't want to install jquery npm module, want to use bower.

Upvotes: 3

Views: 1287

Answers (1)

Ian Lim
Ian Lim

Reputation: 4284

Have you try to use debowerify? If you are using debowerify, your package.json will be simplified as follows:

package.json

{
  "name": "myapp",
  "version": "0.0.1",
  "scripts": {
    "start": "node app"
  },
  "repository": {
    "type": "git",
    "url": "[email protected]:me/myapp"
  },
  "dependencies": {
    "debowerify": "^0.8.1",
    "grunt": "^0.4.5",
    "grunt-browserify": "^3.0.1",
  },
  "engines": {
    "node": "0.10.x"
  },
  "browserify": {
    "transform": [
      "debowerify"
    ]
  }
}

Gruntfile.js and public/javascripts/app.js can still the same as above

Upvotes: 1

Related Questions