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

parameter in import() contains a variable, the file path will not be found after packing. #16493

Open
7 tasks done
yonecdeng opened this issue Apr 22, 2024 · 3 comments
Open
7 tasks done
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@yonecdeng
Copy link

Describe the bug

If the parameter in Import() contains a variable, the file path will not be found after packing.
raw code:
image
after build and run in web:
image

Reproduction

https://stackblitz.com/edit/vitejs-vite-f7q285?file=main.js,test%2Ftest.js&terminal=dev

Steps to reproduce

No response

System Info

System:
    OS: macOS 14.0
    CPU: (12) arm64 Apple M2 Pro
    Memory: 260.98 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.20.0 - ~/.nvm/versions/node/v16.20.0/bin/node
    npm: 8.19.4 - ~/.nvm/versions/node/v16.20.0/bin/npm
    pnpm: 8.11.0 - ~/.nvm/versions/node/v16.20.0/bin/pnpm
  Browsers:
    Chrome: 124.0.6367.61
  npmPackages:
    vite: ^4.4.9 => 4.5.2

Used Package Manager

pnpm

Logs

No response

Validations

Copy link

stackblitz bot commented Apr 22, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@boldurean
Copy link

That's a know issue I guess. #14102

@bluwy bluwy added p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Apr 29, 2024
@bluwy
Copy link
Member

bluwy commented Apr 29, 2024

Seems like a bug we didn't anticipate. When Vite sees the ${} it assumes that the dynamic import has variables and try to transform as:

const result = import.meta.glob('./...')

result[`./test/test.js?key=${g}1`]

But the problem is that result only contains the ./test/test.js key. We may need to fix this but skipping the import.meta.glob flow if the ${} is only on the query param side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

3 participants