vite icon indicating copy to clipboard operation
vite copied to clipboard

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

Open yonecdeng opened this issue 1 year ago • 3 comments

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

yonecdeng avatar Apr 22 '24 10:04 yonecdeng

That's a know issue I guess. #14102

boldurean avatar Apr 22 '24 15:04 boldurean

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.

bluwy avatar Apr 29 '24 10:04 bluwy