1

I am planning to use bootstrap so I first imported jquery.min file by using require() in main.js However, bootstrap throws an error like Bootstrap's JavaScript requires jQuery even I imported the jquery file before bootstrap.

main.js:

import vueResource from 'vue-resource';
import VueHead from 'vue-head';
import Vue from 'vue';
import router from './router';

require('../node_modules/bootstrap/dist/css/bootstrap.min.css');
require('../node_modules/font-awesome/css/font-awesome.min.css');
require('../node_modules/simple-line-icons/css/simple-line-icons.css');
require('./assets/css/app.css');

require('../node_modules/jquery/dist/jquery.min');
require('../node_modules/bootstrap/dist/js/bootstrap.min');
.....

I installed bootstrap(version 3.3.7) and jquery(version 3.2.1) from npm.

What is the correct way to import jquery so bootstrap won't throw the not found jquery error?

3
  • I don't think jquery.min or bootstrap.min will work. .min is just a version of the file that has all unnecessary characters removed in order to make the file size smaller. You still need to indicate what type of file this is. Looks like you just need to add .js after both jquery.min and bootstrap.min. Commented Oct 3, 2017 at 21:07
  • adding .js after both of them didn't change anything. I am using WebStorm application to build the project. It actually wrote that path without .js Commented Oct 3, 2017 at 21:10
  • Ah, interesting. Unfortunately I don't have any experience with WebStorm. I did, however, come across this SO post that may help. Commented Oct 3, 2017 at 21:15

1 Answer 1

1

You need to expose jQuery globally so that bootstrap can initialise using jQuery object.

Try this:

window.jQuery = window.$ =require('../node_modules/jquery/dist/jquery.min')
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.