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

230
Visualizações
What is the correct way to import esm/dist modules? (React/javascript)

So we're using the geist component library in our codebase. It's pretty much integrated into parts of our app and since this library is 250kb, it's impacting our page speed. To circumvent importing the entire module, the usual solution is just importing what you need and ideally, nothing should break and everything should work as expected.

import { CssBaseline } from "@npkn/geist-react"

Doing the above should work but adds 250kb to the bundle.

Another way to import a component would be to import the specific file. I get two options to import the component from either ESM or dist modules

import CssBaseline from "@npkn/geist-react/dist/css-baseline"

and

import CssBaseline from "@npkn/geist-react/esm/css-baseline/index"

I've tried doing both of these but webpack throws errors. I've tried importing named exports as well but even then it throws an error.

TypeError: _npkn_geist_react_dist_css_baseline__WEBPACK_IMPORTED_MODULE_0___default(...).flush is not a function
   9 |   static async getInitialProps(ctx) {
  10 |     const initialProps = await Document.getInitialProps(ctx)
> 11 |     const styles = CssBaseline.flush()
     |                   ^
  12 | 
  13 |     return {
  14 |       ...initialProps,

My question is am I doing the imports right or is there something I'm missing?

Thank you!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If anyone else comes across this question, please check out the bundle size example https://geist-ui.dev/en-us/guide/bundle-size. The example doesn't quite work but I found this work around https://spectrum.chat/geist-ui/react/minimize-build~d30af727-2b97-4d16-9357-9b4e5104fdc9

Instead of doing

import Button from '@geist-ui/react/esm/button'

do

import Button from '../../../../node_modules/@geist-ui/react/esm/button';

Reduced our bundle size significantly!

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