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

460
Views
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
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!