2

File: test.jsx compiles to bundle.js using Gulp and Browserify.

File: test.jsx:

var $ = require('jquery');

$("div#addTagModal").modal("hide");

In browser when I load the page I get this error:

Uncaught TypeError: undefined is not a function 

On this line:

    $("div#addTagModal").modal("hide");

I have no clue what is wrong. :/

$.ajax works fine so I assume that jQuery is loaded properly.

Bootstrap is included in html using a script tag and I have checked the ID of modal.

I have a button that once clicked opens that modal:

<button className="btn btn-success" data-toggle="modal" href="#addTagModal" type="button">
     <i class="icon-plus"></i>
</button>

Any ideas?

This is my gulp task:

gulp.task('browserify', function() {
gulp.src('app/assets/js/main.js')
    .pipe(browserify({
        debug : true,
        transform: ['reactify']
    }))
    .on('error', gutil.log)
    .pipe(rename('public/js/bundle.js'))
    .pipe(gulp.dest('./'))
});

And in main.js I have this code:

var app = require('./test.jsx');
6
  • As modal is not a jQuery object's method, you have to include the related bootstrap scripts in your module. If you are using a script tag for loading bootstrap, do it for jQuery lib too, as jQuery should be loaded before it's plugins. Commented Oct 24, 2014 at 16:15
  • How do I include bootstrap for jquery in browserify? I have tried doing var Bootstrap = require('bootstrap') but it does not work. Commented Oct 24, 2014 at 16:25
  • Browserify with twitter bootstrap Commented Oct 24, 2014 at 16:26
  • I have seen that post but I don't understand what am I supposed to do to make it work :/ Commented Oct 24, 2014 at 16:28
  • There are other related questions too. Adding bootstrap.js to browserify?, Using Bootstrap 3.0 with Browserify Commented Oct 24, 2014 at 16:37

1 Answer 1

-2

Check the file loading. Where your bootstrap.js file is loaded and where your script is loaded. I faced same type of issue and I checked too. It resolved my problem. You may need to check. Hope this helps

Sign up to request clarification or add additional context in comments.

Comments

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.