vite
vite copied to clipboard
parameter in import() contains a variable, the file path will not be found after packing.
Describe the bug
If the parameter in Import() contains a variable, the file path will not be found after packing.
raw code:
after build and run in web:
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
- [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.
That's a know issue I guess. #14102
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.