vite
vite copied to clipboard
v3 `import()` and v2 `import()` behavior is inconsistent
Describe the bug
Related issues: #9179
Describe
The final path is ../components/Com1.vue
, but glob result is missing ../components
. This is valid in vite2
.
I don't know if this is a break changes
or a bug
, and I don't see any documentation mentioning it.
Reproduction
https://stackblitz.com/edit/vitejs-vite-mtfend?file=src/components/Test.vue
System Info
System:
OS: Linux 5.0 undefined
CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.10 - /bin/yarn
npm: 7.17.0 - /bin/npm
npmPackages:
@vitejs/plugin-vue: ^3.0.1 => 3.0.1
vite: ^3.0.1 => 3.0.2
Used Package Manager
pnpm
Logs
No response
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
import | v2 (dev) | v2 (build) | v3 (dev) | v3 (build) |
---|---|---|---|---|
import(`./${name}.vue`) |
warning (cannot be analyzed by vite) | warning (Variable imports cannot import their own directory) + error (failed to fetch) | warning (Variable imports cannot import their own directory) | warning (Variable imports cannot import their own directory) + error (failed to fetch) |
import(`./Com${name}.vue`) |
works | works | works | works |
import(`../components/${name}.vue`) |
works | works | runtime error (Unknown variable dynamic import) | runtime error (Unknown variable dynamic import) |
At least, this should show warning (Variable imports cannot import their own directory) or work.
At least, this should show warning (Variable imports cannot import their own directory) or work.
Agreed, I would prefer it to work😜.
Same Problem. I reverse vite to v2 now.
~~Now I just noticed that this is a bug in import.meta.glob
.😂~~ I misunderstood
I have the same issue that I ran into runtime error (Unknown variable dynamic import)
I found this plugin https://github.com/vite-plugin/vite-plugin-dynamic-import#readme it works for me but not sure if it breaks anything else. Preferably this bug should be fixed since it looks to me like a regression.
Same error with ../ import in Vite3.
I found this plugin https://github.com/vite-plugin/vite-plugin-dynamic-import#readme it works for me but not sure if it breaks anything else. Preferably this bug should be fixed since it looks to me like a regression.
@ahnpnl adding this plugin did the trick, good workaround for now :-)