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

229
Views
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 answers
Answer question

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 Report
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!