Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
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 Respostas
Responde à pergunta

0

I solved it by adding

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

To my webpack.config.js

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda