vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
68.15k stars 6.15k forks source link

Dynamic import vars fail in dev #1461

Closed johannschopplich closed 3 years ago

johannschopplich commented 3 years ago

⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.

Describe the bug

Dynamic imports with variables have been working in Vite 1. In the latest version of Vite 2 errors are thrown in development mode — Vite seems unable to find the related file, although path's are correct. Building the app works fine.

The following code generates the routes:

const routes = [
  ...site.children.map(page => ({
    path: `/${page.uri}`,
    component: () => import(`../views/${capitalize(page.template)}.vue`).catch(() => Default)
  }))
]

Vite displays error messages like:

Failed to load url /views/Home.vue (resolved id: /views/Home.vue). Does the file exist?

Regular imports work just fine:

import Default from '../views/Default.vue'

I think some suffix is missing. Vite calls /views/Home.vue?import and cuts off everything after "import". It probably should look similar to /src/views/Default.vue?vue&type=style&index=0&scoped=true&lang.css.

Thanks in advance for taking a look!

Reproduction

System Info

Logs (Optional if provided reproduction)

21:36:42 [vite] Internal server error: Failed to load url /views/Home.vue (resolved id: /views/Home.vue). Does the file exist?
[1]   Error: Failed to load url /views/Home.vue (resolved id: /views/Home.vue). Does the file exist?
[1]       at transformRequest (/Users/johann/Git/kirby-vue3-starterkit/node_modules/vite/dist/node/chunks/dep-4a623736.js:66414:15)
[1]       at /Users/johann/Git/kirby-vue3-starterkit/node_modules/vite/dist/node/chunks/dep-4a623736.js:66510:32
[1] 2021-01-09T20:36:42.316Z vite:time 2ms   /views/Home.vue?import
revolist commented 3 years ago

Describe the bug

Relative library import still doesn't work for me

 [vite] Internal server error: Failed to resolve import ".entry.js". Does the file exist?
  Plugin: vite:import-analysis
  File: /Users/maks/Projects/revo-vite/vite-project/node_modules/.vite/@revolist_revogrid_loader.js?v=d36e8090
  1519|      return o[r];
  1520|    }
  1521|    return import("./" + a + ".entry.js").then(function(e2) 

The library has relative reference which vite can't read.

Steps

System Info

vite version: 2.0.0-beta.64 Operating System: macOS Catalina Node version: 15.3.0 Package manager (npm/yarn/pnpm) and version: npm 7.0.14