floatThead: jQuery is not defined when using with browserify

I tried using the npm package inside my project that uses browserify and babelify and the script complains that jQuery is not defined, even though it IS imported and both defined as const jQuery in the file where floatThead is used, and in the window scope as window.jQuery and window.$ (required for bootstrap)

I tried with import 'floatthead' and require('floatthead') but in both cases, the script complains that jQuery is not defined. Why not make a proper module?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Confirming that it’s working! For anyone wondering

In package.json

"devDependencies": {
  "browserify": "^13.1.0",
  "browserify-shim": "^3.8.12",
  "grunt-browserify": "^5.0.0"
  /* ... */
},
"browser": {
  "jquery": "./node_modules/jquery/dist/jquery.min.js"
},
"browserify": {
  "transform": [
    "browserify-shim"
  ]
},
"browserify-shim": "./shims.js"

shims.js

module.exports = {
  jquery: { exports: 'jQuery' }
}

in Gruntfile.js

browserify: {
  dist: {
    options: {
      browserifyOptions: {
        debug: true
      },
      transform: [
        'browserify-shim'
      ]
    },
    src: ['src/js/main.js'],
    dest: 'dist/js/app.js'
  }
},

Not sure if it’s needed in the gruntfile though, but it works like so.