Select2 is not a function


#1

I’m trying to use select2 through webpack.
Here’s what I get :

TypeError: $(...).select2 is not a function

My package.json :

{
“name”: “exportmenu”,
“version”: “1.0.0”,
“description”: “Webpack project starter including Foundation framework.”,
“main”: “index.js”,
“scripts”: {
“dev”: “./node_modules/.bin/webpack --config ./build/webpack.dev.js -d --watch”,
“prod”: “./node_modules/.bin/webpack --config ./build/webpack.prod.js”,
“proxy”: “./node_modules/.bin/browser-sync start --config ./build/proxy.dev.json”
},
“author”: “Ice dev”,
“license”: “ISC”,
“devDependencies”: {
“babel-core”: “^6.26.0”,
“babel-loader”: “^7.1.2”,
“babel-preset-env”: “^1.6.0”,
“browser-sync”: “^2.18.13”,
“css-loader”: “^0.28.7”,
“extract-text-webpack-plugin”: “^3.0.0”,
“motion-ui”: “^1.2.3”,
“node-sass”: “^4.5.3”,
“postcss-cssnext”: “^3.1.0”,
“postcss-loader”: “^2.0.6”,
“sass-loader”: “^6.0.6”,
“script-loader”: “^0.7.2”,
“style-loader”: “^0.18.2”,
“webpack”: “^3.6.0”
},
“dependencies”: {
“expose-loader”: “^0.7.4”,
“foundation-sites”: “^6.4.3”,
“imports-loader”: “^0.7.1”,
“jquery”: “^3.2.1”,
“air-datepicker”: “^2.2.3”,
“slick-carousel”: “^1.7.1”,
“select2”: “4.0.3”
}
}

My main js file :

import ‘script-loader!select2/dist/js/select2.js’;
import ‘script-loader!select2/dist/js/i18n/fr.js’;

$(function () {
$(’.s2’).select2();
});

My html file :

< select class=“s2” name=“codeclient”>
< option value=“tot”>Tous
< option value=“tot”>C1234
< /select>


#2

found my response :

I added import ‘select2’; before
import ‘script-loader!select2/dist/js/select2.js’;
import ‘script-loader!select2/dist/js/i18n/fr.js’;

in my main js file