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

483
Visualizações
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
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