0

I am recently working on projects using Webpack, JS and Bootstrap, but suddenly on the project I am currently working on, and despite using the same Webpack and npm configs the bootstrap Javascript stopped working, although It shows in the javascript bundle in the Sources tab in the browser.

Notes:

  • All my .js files and styles in the entry file i.e index.js work fine and all libraries, too.
  • The order of imported files is:
    1. jquery
    2. popper.js
    3. bootstrap.min.js
  • Using CDNs for both Jquery and Bootstrap instead of imports did not fix the problem.

Here is the code on GitHub: https://github.com/WeamAdel/webpack-template

Webpack.config.js:

module.exports = {
  entry: {
     main: "./src/index.js",
     home: "./src/assets/js/home.js",
  },

  output: {
   // filename: "assets/js/[name].[fullhash:7].js",
    path: path.resolve(__dirname, "build"),
  },

  devServer: {
    port: 9000,
    contentBase: path.resolve(__dirname, "build"),
  },

  module: {
    rules: [
      //JS
      {
        test: /\.m?js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: "babel-loader",
          options: {
          presets: ["@babel/preset-env"],
        },
      },
   },

  // HTML
  {
    test: /\.html$/i,
    loader: "html-loader",
  },

  //Pug
  {
    test: /\.pug$/i,
    use: ["html-loader", "pug-html-loader"],
  },
   ],
 },

 plugins: [
     new HtmlWebpackPlugin({
        template: "./src/index.pug",
        chunks: ["main", "home"],
     }),
     new CleanWebpackPlugin(),
  ],

  optimization: {
     minimize: true,
     minimizer: [
        `...`,
        new CssMinimizerPlugin(),
    ],
  },

};

index.js

import "jquery";
import "popper.js";
import "bootstrap/dist/js/bootstrap.min";
5
  • It would be helpful if you could show the webpack code in question directly Commented Jan 26, 2021 at 22:46
  • @Pytth I have just added snippets from Webpack.confing.js and index.js Commented Jan 27, 2021 at 13:04
  • How has it "stopped working?" Are you getting errors? Is nothing happening? Does the page take longer to load? More details por favor :) Commented Jan 27, 2021 at 16:24
  • No errors and It does not take long to load. Dropdowns, Navbar collapses just does not do anything when I click them. Commented Jan 28, 2021 at 13:42
  • Can you please show the HTML that would hold the script tag(s) for the built package(s)? Commented Jan 28, 2021 at 16:12

2 Answers 2

2

Came across this topic finding a solution for the same symptoms. In my case the problem was, I had bootstrap version 4.6.0 installed, but copied and paste code snippets for version 5.0.

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

1 Comment

Yes, this was the problem, I have been trying to fix it for 4 months now :'D, thank you so much, that really helped me.
1

Make sure to install the (exact) version of bootstrap and add your classes accordingly.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.