You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using import.meta.glob('./*.json', { eager: true }); to import a json like the following, I am unable to access the second key-value. I'm not sure if it's related to the space in the key, but removing it allows the key to be accessed as expected.
The first one is accessible via glob["./sample.json"]["hello"], however glob["./sample.json"]["hello world"] returns undefined.
Importing the json with the options {eager: true, as: "raw"} and then grabbing the json via JSON.parse() on the raw string is how I'm currently sidestepping this problem.
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
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.
hello world is not a valid identifier and therefore it wasn't possible to declare a named export like that.
Thanks to the "arbitrary module namespace identifier names" feature, it's now possible but it's not supported yet.
You can access it by glob["./sample.json"].default["hello world"] as a workaround.
Or you can use import.meta.glob('./*.json', { eager: true, import: 'default' }).
Describe the bug
When using
import.meta.glob('./*.json', { eager: true });
to import a json like the following, I am unable to access the second key-value. I'm not sure if it's related to the space in the key, but removing it allows the key to be accessed as expected.The first one is accessible via
glob["./sample.json"]["hello"]
, howeverglob["./sample.json"]["hello world"]
returnsundefined
.Importing the json with the options
{eager: true, as: "raw"}
and then grabbing the json viaJSON.parse()
on the raw string is how I'm currently sidestepping this problem.Reproduction
https://stackblitz.com/edit/vitejs-vite-egdnir?file=main.js
Steps to reproduce
No response
System Info
System: OS: Linux 5.0 undefined CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 16.20.0 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 9.4.2 - /usr/local/bin/npm pnpm: 8.6.10 - /usr/local/bin/pnpm npmPackages: vite: ^4.4.9 => 4.4.9
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: