jQuery module not found using jquery-slim package?
Asked Answered
F

1

7

I am using Laravel framework with laravel-elixir, jquery-slim, vuejs, vue-resource npm packages.

My issue is that when I try to import a jquery plugin (ex. snackbarjs) its giving me an issue since the jquery module is not being recognised.

The error:

Browserify Failed!: Cannot find module 'jquery'

I know where the problem comes from, the snackbarjs in this case tries to require the jquery plugin using this code:

(function (factory) {
if (typeof define === 'function' && define.amd) {
    // AMD. Register as an anonymous module.
    define(['jquery'], factory);
} else if (typeof exports === 'object') {
    // Node/CommonJS
    module.exports = factory(require('jquery'));
} else {
    // Browser globals
    factory(jQuery);
}

My app.js file looks like this:

import $ from 'jquery-slim';
import jQuery from 'jquery-slim';
import Vue from 'vue';
import VueResource from 'vue-resource';
import Vuex from 'vuex';
import 'snackbarjs';
Vue.use(VueResource);
Vue.use(Vuex);

Is there a way for snackbarjs to ignore the 'jquery' module requirement or to change the name of the module to 'jquery' from 'jquery-slim'?

Thanks in advance!

Flinders answered 7/7, 2016 at 8:38 Comment(0)
G
0

try import 'jquery/dist/jquery.slim.js'

you can find more info on this page

Geosphere answered 5/11, 2018 at 7:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.