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

464
Visualizações
MERS STACK with Webpack - ReferenceError: require is not defined in ES module scope

i am starting learning to create dev env using webpack and MERN

i am doing the same as in this article https://blog.bitsrc.io/an-efficient-way-to-set-up-a-mern-stack-application-12fd87fad90d

but i like to use import in the place of require so i added "type": "module" in packege.json

 "name": "diamond-dev-ecosystem",
  "version": "1.0.0",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "dev": "nodemon",
    "build": "webpack --config webpack.config.client.production.js && webpack --mode=production --config webpack.config.server.js",
    "start": "NODE_ENV=production node ./dist/server.generated.js"
    },

and in .babelrc

{
"presets": [
    ["@babel/preset-env",
        {
            "targets": {
                "node": "current"
            }
        }
    ],
"@babel/preset-react"
],
"plugins": [
    "react-hot-loader/babel"
]

}

but i have this error: ReferenceError: require is not defined in ES module scope, you can use import instead [error message][1]

because in my code i use import but the generated code from webpack use require

so how i can fixe this probleme will still using import, if possible ?

Note: if you have any advice for creating dev env, i will be thankful

thanks [1]: https://i.stack.imgur.com/2urPo.png

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