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

482
Views
How can I import a js module, instead of require()?

I have a react web app which is compiled with webpack 5. I am using material-ui as a component library.

In my code I have always used require() to import components.

for example:

const { IconButton, ThemeProvider, createTheme, Box } = require('@material-ui/core');

However, I need to move over to use import instead of require.

So it should look like this:

import { IconButton, ThemeProvider, createTheme, Box } from '@material-ui/core';

When doing so, webpack successfully bundles everything, but when I try loading the app in chrome, I just get an error:

Uncaught Error: ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: ./src/component/App.js

What needs to be true in order to be able to make this work? I am sure I need to provide more information about either my webpack configuration or how my react app was created, but I am kind of clueless to what to look for, so If someone could start asking for the information I am missing in this question, then I will update with more information.

Thanks!

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!