Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

352
Views
Uncaught ReferenceError: jQuery is not defined in Webpack

I'm trying to dynamically inject the header with Jquery inside the index.html but the console reports an error:

Uncaught ReferenceError: jQuery is not defined

I'm making several attempts but the problem persists, would anyone be able to help me?

webpack.confing.js

...
    plugins: [].concat(
        pages.map(
            (page) =>
                new HtmlWebpackPlugin({
                    inject: true,
                    template: `./src/html/${page}.html`,
                    filename: `./src/html/${page}.html`,
                    chunks: [page],
                })
        ),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery"
        }),
    ),
    devServer: {
      watchContentBase: true,
      contentBase: path.resolve(__dirname, 'dist'),
      open: true
    },
    externals: {
        jquery: 'jQuery'
    },
    mode: 'production',
};

index.js

import '../css/style.css';
import '../css/style.scss';
import Icon from '../resources/img/icon.png';
require('jquery');
window.$ = jQuery;

index.html

<div>${require('../includes/header.html')}</div>
<h1 class="hello">Lorem ipsum</h1>
<p>Lorem ipsum dolor sit amet</p>
<img src="../resources/img/icon.png" alt="img home"/>
<div>${require('../includes/footer.html')}</div>

package.json

...
  "devDependencies": {
    "clean-webpack-plugin": "^4.0.0",
    "css-loader": "^6.7.1",
    "file-loader": "^6.2.0",
    "html-loader": "^3.1.0",
    "html-webpack-plugin": "^5.5.0",
    "sass": "^1.49.9",
    "sass-loader": "^12.6.0",
    "style-loader": "^3.3.1",
    "webpack": "^5.70.0",
    "webpack-cli": "^4.9.2",
    "webpack-dev-server": "^4.7.4"
  },
  "dependencies": {
    "jquery": "^3.6.0",
    "jquery-ui": "^1.13.1"
  }
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!