question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamic glob imports does not work with vite

See original GitHub issue

Environment


  • Operating System: Linux
  • Node Version: v14.16.0
  • Nuxt Version: 3.0.0-27265876.3cd4494
  • Package Manager: npm@7.17.0
  • Bundler: Vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Describe the bug

Unpredictable dynamic imports like import(~/data/${name}json)` does not work with vite (dev-bundler)

Reproduction

https://stackblitz.com/edit/github-obezmd?file=app.vue

Additional context

As a workaround, one can use webpack using vite: false in nuxt.config.

Missing implementation is here but we probably need more to fix this.

Logs

Cannot read properties of undefined (reading 'stubModule')
at __instantiateModule__ (file://./.nuxt/dist/server/server.mjs:1771:11)
at __ssrLoadModule__ (file://./.nuxt/dist/server/server.mjs:1762:25)
at ssrImport (file://./.nuxt/dist/server/server.mjs:1787:13)
at ssrDynamicImport (file://./.nuxt/dist/server/server.mjs:1798:12)
at eval (file://./.nuxt/dist/server/server.mjs:1678:70)
at Module.withAsyncContext (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7295:21)
at setup (file://./.nuxt/dist/server/server.mjs:1678:47)
at _sfc_main.setup (file://./.nuxt/dist/server/server.mjs:1708:23)
at callWithErrorHandling (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6615:22)
at setupStatefulComponent (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6241:29)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:23 (6 by maintainers)

github_iconTop GitHub Comments

9reactions
AbrahemAlhofecommented, Dec 6, 2021

Is there is any update on this issue because i have the same problem

3reactions
caoxiemeihaocommented, Jul 28, 2022

Now, I try to use vite-plugin-dynamic-import to resolve this problem.
But in the end, I hope it can be integrated into vite.

import { defineNuxtConfig } from 'nuxt3';
import dynamicImport from 'vite-plugin-dynamic-import';

// https://v3.nuxtjs.org/docs/directory-structure/nuxt.config
export default defineNuxtConfig({
  vite: {
    plugins: [
      dynamicImport(),
    ],
  },
});


2022-07-28

You may got the following error.

ERROR Unexpected token (1:0)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Features
You can NOT use variables or expressions in them. Dynamic Import #. Similar to glob import, Vite also supports dynamic import with variables....
Read more >
Glob Imports in Vite - A Vue.js Lesson From our ...
In this lesson, we learn how to import multiple modules at one time using a glob pattern. Matched modules can be imported either...
Read more >
vite & react import images dynamically from public url
First you need to adjust the path that you pass to the import.meta.glob function. Specify a path relative to the file that this...
Read more >
Problem configuring dynamic page importing with Vite and ...
I'm working on an app with AdonisJS as a backend, Inertia , Vue 3 and Vite to bundle assets. The problem is, I...
Read more >
vite-plugin-dynamic-import
vite -plugin-dynamic-import. TypeScript icon, indicating that this package has built-in type declarations. 1.2.4 • Public • Published a month ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found