Skip to content
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

v3 import() and v2 import() behavior is inconsistent #9265

Closed
7 tasks done
Dunqing opened this issue Jul 21, 2022 · 8 comments · Fixed by #9350
Closed
7 tasks done

v3 import() and v2 import() behavior is inconsistent #9265

Dunqing opened this issue Jul 21, 2022 · 8 comments · Fixed by #9350
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority)

Comments

@Dunqing
Copy link
Contributor

Dunqing commented Jul 21, 2022

Describe the bug

Related issues: #9179

Describe

image

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

@sapphi-red
Copy link
Member

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.

@sapphi-red sapphi-red added p2-edge-case Bug, but has workaround or limited in scope (priority) and removed pending triage labels Jul 21, 2022
@Dunqing
Copy link
Contributor Author

Dunqing commented Jul 21, 2022

At least, this should show warning (Variable imports cannot import their own directory) or work.

Agreed, I would prefer it to work😜.

@m430
Copy link

m430 commented Jul 23, 2022

Same Problem. I reverse vite to v2 now.

@Dunqing
Copy link
Contributor Author

Dunqing commented Jul 24, 2022

Now I just noticed that this is a bug in import.meta.glob.😂 I misunderstood

@ahnpnl
Copy link

ahnpnl commented Jul 29, 2022

I have the same issue that I ran into runtime error (Unknown variable dynamic import)

@ahnpnl
Copy link

ahnpnl commented Aug 1, 2022

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.

@dergunovs
Copy link

Same error with ../ import in Vite3.

@olemarius
Copy link

olemarius commented Aug 9, 2022

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 :-)

@github-actions github-actions bot locked and limited conversation to collaborators Aug 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants