0

I am using dynamic import in next js. The component is rendered when I directly use the path. But it is not rendering when I use the path from a variable.

const faq = dynamic(() => import('../faq/faq'))

This works fine. but,

const path = '../faq/faq';
const faq = dynamic(() => import(path ))

This is not working. How can I fix this?

noufalcep
  • 3,446
  • 15
  • 33
  • 51

2 Answers2

0

As Per webpack Documentation It is not possible to use a fully dynamic import statement, such as import(foo). Because foo could potentially be any path to any file in your system or project.

-1

You can use string concatenation while importing dependencies from variable

const path = '../faq/faq';
const faq = dynamic(() => import(`${path}` ))
Prathap Parameswar
  • 489
  • 1
  • 3
  • 11