Next.js Discord

Discord Forum

pattern into an exports field is not implemented yet

Answered
Narrow-barred Spanish mackerel posted this in #help-forum
Open in Discord
Narrow-barred Spanish mackerelOP
Hey y'all!

I'm using turborepo, pnpm and next.js to build a project. I have a package that exports some components with a key name that is saved in a database. I want to import the components based on the database data, so I can specifically pick the ones that I need instead of importing them all. The exports field in package.json of @repo/page looks like this:
{
// ...
"exports": {
    "./blocks/*": "./src/blocks/*",
    "./types": "./src/types.ts"
  },
// ....
}

I also tried explicitly exporting the block key (e.g. ./blocks/hero), but that didn't work either. I know that the error says not implemented yet, but is there any workaround to this? And is there an issue tracking this?
Answered by Narrow-barred Spanish mackerel
I found a workaround by making a function in @repo/page that executes an import command
const importBlock = (blockName: string) => import(`./${blockName}`).then(mod => mod.default);

I very much hate this, but at least this avoids manually importing every single component that might be required
View full answer

2 Replies

Narrow-barred Spanish mackerelOP
Debug Info if that helps
Narrow-barred Spanish mackerelOP
I found a workaround by making a function in @repo/page that executes an import command
const importBlock = (blockName: string) => import(`./${blockName}`).then(mod => mod.default);

I very much hate this, but at least this avoids manually importing every single component that might be required
Answer