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?

0

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

-1

You can use string concatenation while importing dependencies from variable

const path = '../faq/faq';
const faq = dynamic(() => import(`${path}` ))

1 Comment

along with dynamic import, you can use suspense or loading fallback based on your react version.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.