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
Cannot read properties of undefined (reading 'stubModule') #10345
Comments
I'm unsure if dynamic import actually supports anything other than string literals. I think CommonJS require() supports this however Nuxt3 isn't allowing any files I use in the /plugins directory to use cjs syntax. |
Thanks for your contribution to Nuxt!
Issues that are labeled as |
If anyone runs into this issue I found out a while ago that you can only use dynamic import for file names or after the first folder in import, I believe, so this isn't a Nuxt issue, I thought it was something to do with cjs/es module differences and Nuxt3 not allowing me to import cjs files as plugins etc. I'm not sure of all the nuances but using: const componentName = 'Logo'
console.log(await import(`~/components/${componentName}`)) Should hopefully work. You also have to wrap the component and get it's default: (await import(`~/components/${componentName}`)).default |
I just tried this and that did not work :
But this works :
|
What is odd is that it work for the client in dev mode, if you guard the code with |
Versions
Reproduction
I am dynamically trying to import components but for some reason I can only import with a static url. Trying to do so using a variable name causes the error.
Works:
Doesn't work:
Steps to reproduce
I am calling the above code from the plugins directory in Nuxt3.
What is Expected?
Should return the component.
What is actually happening?
Throws this error:
The text was updated successfully, but these errors were encountered: