Next.js Discord

Discord Forum

How to modularize imports from a barrel file that exports from multiple directories in Next.js

Unanswered
Catla posted this in #help-forum
Open in Discord
CatlaOP
I would like to use the [modularizeImports](https://nextjs.org/docs/architecture/nextjs-compiler#modularize-imports) option of the Next.js compiler on a library that its barrel file exports from multiple directories within the library package.

What I mean is the index.ts file for the library looks something like this:

//index.ts
export {default as SomeComponent} from './components/SomeComponent';
export {default as someFun} from './utils/someFunction';
export {default as someHook} from './hooks/someHook';


ideally I would like to have something like this

//next.config.js
  modularizeImports: {
    '@some/library': {
      transform: '@some/library/dist/(components|hooks|utils)/{{member}}',
    },
  },


but

1. I am not sure if this functionality is even possible
1. if it is I am not sure how to to write it.

I also tried passing it an array of transforms but it only accepts a single string.

Under the hood this option is implemented with https://docs.rs/handlebars/latest/handlebars/ afaik

1 Reply

CatlaOP
@White-throated Swift could you help me on this ?