Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[AssetMapper] Add support for loading JSON using import statements#61133
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:7.4
Are you sure you want to change the base?
Conversation
a5a31cb
to12eba70
CompareUh oh!
There was an error while loading.Please reload this page.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Kocal commentedJul 16, 2025 • edited by nicolas-grekas
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by nicolas-grekas
Uh oh!
There was an error while loading.Please reload this page.
Switched to a project with AssetMapper correctly installed, the following code importjsonfrom'./foo.json'with{type:'json'};console.log(json) with the patch suggested in#61133 (review) correctly resolves the JSON |
nicolas-grekas commentedJul 16, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This PR is about this: -import json from './foo.json' with {type: 'json'};+import jsonPromise from './foo.json'; and then (note the await): console.log(awaitjsonPromise); |
Ah, fine then |
We should skip using the loader when |
Uh oh!
There was an error while loading.Please reload this page.
This is inspired byhttps://web.dev/blog/json-imports-baseline-newly-available
Modern browserssupport loading JSONs via the
import data from './foo.json' with {type: 'json'}
syntax. While this has been promoted as a new baseline, that's still not widely supported.This PR proposes to add support for a more portable alternative using
import jsonPromise from './foo.json'
instead, with some server-side assisted loader.On the client-side, one could then use the imported data by awaiting it first (the import returns a Promise):
json = await jsonPromise
Note that we already support importing css via import statements.
Native support for
import './foo.css' with {type: 'css'}
exists, but that'seven less available.