Browserify bundle undefined dependency

steo

I'm using browserify in a Backbone project and shimming owlCarousel because it is not a commonJS like module. The shim transformation seems to work but not when I really need it.

My app.js file looks like:

var settingsView = require("./settingsView.js");

new settingsView();

and my settingsView

var app = require("./controllers.js"),
    $ = require("jQuery"),
    Backbone = require("Backbone"),
    owlCarousel = require("owlCarousel");
    Backbone.$ = $;

module.exports = Backbone.View.extend({
   el: ".settings",

   events: {
    "click .carousel-img": "setBackground",
    "click .palette div": "setTextColor"
   },

   options: {
    singleItem: true,
    pagination: false,
    navigation: true,
    mouseDrag: false
   },

   initialize: function () {
     this.initCarousel();
   },

   initCarousel: function () {
     /* This is causing the problem */
      this.owlCarousel = this.$el.find(".carousel").owlCarousel(this.options);
   }
})

where my package.json

"browser": {
    "jquery": "./node_modules/jquery/dist/jquery.js",
    "owlCarousel": "./vendor/owl-carousel/owl-carousel/owl.carousel.js"
   },
   "browserify": {
    "transform": [
      "browserify-shim"
    ]
   },
   "browserify-shim": {
    "jquery": "$",
    "owlCarousel": {
      "depends": ["jquery:$"]
    }
   }

The error it's giving me:

Uncaught TypeError: this.$el.find(...).owlCarousel is not a function

at runtime. But, if I run $("div").owlCarousel in the console after dom ready, it works.

steo

I solved doing

var app = require("./controllers.js"),
    $ = require("jQuery"),
    Backbone = require("Backbone"),
    owlCarousel = require("owlCarousel");
    Backbone.$ = $;    
    $.fn.owlCarousel = owlCarousel

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Browserify bundle undefined dependency

From Dev

Karma Browserify bundle error

From Dev

Multiple node modules in a browserify bundle

From Dev

Browserify bundle.js demystified

From Dev

Multiple node modules in a browserify bundle

From Dev

Browserify - create bundle with external module

From Dev

Grunt browserify transform ReactJS then bundle

From Dev

gulp browserify + reactify not creating bundle

From Dev

List files from browserify bundle

From Dev

Bundle dependency on Bundle in Resolved State

From Dev

Sylius Product Bundle as dependency

From Dev

Maven: bundle specific dependency

From Dev

How to use browserify to bundle a backbone app?

From Dev

Where to put 'use strict' in Browserify bundle

From Dev

browserify bundle electron app main process file

From Dev

Making Browserify bundle play nice with ReactDevTools

From Dev

How does the bundle order work in browserify?

From Dev

gulp browserify bundle time takes too long

From Dev

How to bundle multiple javascript libraries with browserify?

From Dev

Running multiple transforms on gulp/browserify bundle

From Dev

Why is it necessary to install Browserify twice to bundle

From Dev

Browserify, is it possible to bundle common modules into seperate file?

From Dev

Making Browserify bundle play nice with ReactDevTools

From Dev

Why is it necessary to install Browserify twice to bundle

From Dev

Browserify produces an unusable bundle.js

From Dev

Circular dependency issue with Typescript, CommonJS & Browserify

From Dev

using global for dependency with grunt-browserify

From Dev

using global for dependency with grunt-browserify

From Dev

Exporting internal library dependency to outer scope with browserify

Related Related

HotTag

Archive