Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

363
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda