Using import() dynamically not working
Unanswered
Siberian posted this in #help-forum
SiberianOP
I'm trying to use import() to import a bunch of files to get data from them but nextjs is saying that's not implemented yet so what are the alternatives I can use?
const postsDir = path.join(process.cwd(), "content/posts");
const postFiles = fs.readdirSync(postsDir).filter(f => f.endsWith(".jsx"));
const posts = await Promise.all(
postFiles.map(async (file) => {
const mod = await import(path.join(postsDir, file));
return {
metadata: mod.meta,
Content: mod.default,
};
})
);