Async imports with variables throw error
See original GitHub issueEnvironment
- Operating System:
Linux
- Node Version:
v14.16.0
- Nuxt Version:
3-3.0.0-27237303.6acfdcd
- Package Manager:
npm
- Bundler:
Webpack
- User Config:
-
- Runtime Modules:
-
- Build Modules:
-
Describe the bug
Using dynamic imports with variables throw error. Example
<script setup lang="ts">
import { defineAsyncComponent } from 'vue';
const name = 'test';
const componentId = defineAsyncComponent(
() => import(`./components/${name}.vue`)
);
</script>
Error
Error
[Vue warn]: Unhandled error during execution of async component loader
at <AsyncComponentWrapper>
[Vue warn]: Unhandled error during execution of setup function
at <AsyncComponentWrapper>
Server Side Rendering Error: TypeError: Cannot read properties of undefined (reading 'stubModule')
at __instantiateModule__ (file:///home/projects/github-gyhqth/.nuxt/dist/server/server.mjs:1782:11)
at __ssrLoadModule__ (file:///home/projects/github-gyhqth/.nuxt/dist/server/server.mjs:1773:25)
at ssrImport (file:///home/projects/github-gyhqth/.nuxt/dist/server/server.mjs:1797:13)
at ssrDynamicImport (file:///home/projects/github-gyhqth/.nuxt/dist/server/server.mjs:1808:12)
at eval (file:///home/projects/github-gyhqth/.nuxt/dist/server/server.mjs:1696:74)
at load (/home/projects/github-gyhqth/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:1529:17)
at setup (/home/projects/github-gyhqth/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:1582:24)
at callWithErrorHandling (/home/projects/github-gyhqth/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6599:22)
at setupStatefulComponent (/home/projects/github-gyhqth/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6225:29)
at setupComponent (/home/projects/github-gyhqth/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6181:11)
Reproduction
https://stackblitz.com/edit/github-gyhqth?file=app.vue
Additional context
No response
Logs
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
import() use static string work well but string variable not work ...
When i use a string variable parameter for import(),it dosn't work.And it will throw error: async function fun(){ const path = ".
Read more >Dynamic imports - The Modern JavaScript Tutorial
The import(module) expression loads the module and returns a promise that resolves into a module object that contains all its exports. It can...
Read more >import() - JavaScript - MDN Web Docs - Mozilla
The import() syntax, commonly called dynamic import, is a function-like expression that allows loading an ECMAScript module asynchronously ...
Read more >Module Variables - webpack
This section covers all variables available in code compiled with webpack. ... return await originalLoad(id); } catch (e) { error = e; }...
Read more >ES2020: `import()` – dynamically importing ES modules - 2ality
import () returns Promises, which means that you can use it via async functions (which are part of ECMAScript 2017) and get nicer...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@grindpride I’m wondering if you’ve found a way to go about dynamic icon import with vite? I’m trying to do something similar in Nuxt 3 and its a headache
Any update on this?