tc39 / proposal-import-attributes

Proposal for syntax to import ES modules with assertions
https://tc39.es/proposal-import-attributes/
Apache License 2.0
586 stars 26 forks source link

Trouble with JSON Imports in JavaScript #158

Closed amirfarzamnia closed 5 months ago

amirfarzamnia commented 5 months ago

This problem is about bringing in JSON modules using the 'import' keyword in JavaScript. The code seems to work well on both mobile and computer devices:

import('./index.json', { assert: { type: 'json' }}).then(({ default: json }) => document.body.appendChild(Object.assign(document.createElement('div'), { innerHTML: json.message })));

However, according to the documentation, the 'assert' option is outdated and has been replaced with the 'with' keyword. So, the code should be like this:

import('./index.json', { with: { type: 'json' }}).then(({ default: json }) => document.body.appendChild(Object.assign(document.createElement('div'), { innerHTML: json.message })));

But now, this code only seems to work on computers and won't work on mobile devices anymore!

I think this is a problem that needs fixing.

nicolo-ribaudo commented 5 months ago

What do you mean by "mobile devices"? iOS only supports with, while on Android:

In general, be careful when using proposals because they are never supported everywhere. Hopefully in one year it will be ;)

amirfarzamnia commented 5 months ago

So, this code works fine on Chrome for Windows, but it's not working on the latest version of Chrome on Android. Is this not an issue?

nicolo-ribaudo commented 5 months ago

It's not an issue with the proposal, if anything it's an issue with Chrome that didn't release it yet.

Can you go on your Chrome settings, About Chrome (at the end) and check the version?

amirfarzamnia commented 5 months ago

I got it, my bad.