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

209
Vistas
Webpack config with "target: 'node'" and "type: 'module'" throws 'require is not defined'

When running my webpack config for an express server that uses ES6 modules, has "type": "module" defined in package.json and uses target: 'node' it fails with an an error ReferenceError: require is not defined.

When looking at the processed javascript file i see the following statements that cause this error:

/******/ (() => { // webpackBootstrap
/******/    "use strict";
/******/    var __webpack_modules__ = ({

/***/ "body-parser":
/*!******************************!*\
  !*** external "body-parser" ***!
  \******************************/
/***/ ((module) => {

module.exports = require("body-parser");

/***/ }),

Why does webpack include this code? The server runs totally fine when not processed with webpack.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I solved it by adding

experiments: {
  ...
  outputModule: true,
},
output: {
  ...
  chunkFormat: 'module', 
}

To my webpack.config.js

about 4 years ago · Juan Pablo Isaza Denunciar
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