-
Notifications
You must be signed in to change notification settings - Fork 27.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use Template literals with dynamic import? #4100
Comments
You can't do truly dynamic imports. Webpack can't predict the outcome and prebundle. |
@timneutkens This is not true. Webpack can handle dynamic imports where part of the path is static. From the docs:
This error is specifically a deficiency in |
Lets re-open the issue then. |
Would really love to see this get support added. |
@herrstucki You mean because of the |
@vjpr yes, this line fails with a template literal: https://github.com/zeit/next.js/blob/4881cd346b8155314c02a6996538fb48d324111d/server/build/babel/plugins/handle-import.js#L57 |
@herrstucki is there any solution for this problem? |
I'd just like to add that this is especially useful when trying to internationalize an app since it allows us to split up imports from For reference: formatjs/formatjs#777 (comment) |
Ran into this today while building out a portfolio page on a website. Just thought I'd throw in my experience for more context 😄 I have a <Link href={`/portfolio/item?id=${id}`} as={`/portfolio/${id}`} prefetch> When clicked, the component at static async getInitialProps({ query }) {
const data = await import(`../../portfolio/${query.id}.json`)
return { data }
} But unfortunately I'm getting the same error as above:
Attempting to find a workaround for now. I will update here if I find anything 👍 |
Fixed in #4639 |
How to use Template literals with dynamic import?
const Component = dynamic(import(
/components/${kindOf}))
In console i have error
Module build failed: TypeError ... Cannot read property '0' of undefined
The text was updated successfully, but these errors were encountered: