Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic import with type: 'json' causes syntax error on Firefox #19095

Open
7 tasks done
hyunbinseo opened this issue Dec 29, 2024 · 4 comments
Open
7 tasks done

Dynamic import with type: 'json' causes syntax error on Firefox #19095

hyunbinseo opened this issue Dec 29, 2024 · 4 comments
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@hyunbinseo
Copy link
Contributor

hyunbinseo commented Dec 29, 2024

Describe the bug

const module = () => import('./sample.json', { with: { type: 'json' } }); // breaks
const module = () => import('./sample.json', { assert: { type: 'json' } }); // breaks
const module = () => import('./sample.json'); // works

In Firefox 133.0.3 (aarch64)

Uncaught SyntaxError: missing ) after argument list main.js:6:54

Reproduction

https://stackblitz.com/edit/vitejs-vite-rde9qabm?file=src%2Fmain.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: 18.20.3 - /usr/local/bin/node
  Yarn: 1.22.19 - /usr/local/bin/yarn
  npm: 10.2.3 - /usr/local/bin/npm
  pnpm: 8.15.6 - /usr/local/bin/pnpm

Used Package Manager

npm

Logs

No response

Validations

@JamesParrott

This comment was marked as resolved.

@hi-ogawa
Copy link
Collaborator

@JamesParrott Your issue is likely different and that's babel / react plugin issue vitejs/vite-plugin-react#385 It should be fixed (workarounded) in latest react plugin, so please try it after upgrading it.

@hi-ogawa hi-ogawa changed the title Dynamic import with type: 'json' causes syntax error Dynamic import with type: 'json' causes syntax error on Firefox Dec 31, 2024
@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Dec 31, 2024

Vite doesn't strip off import attributes for dynamic import, so the browsers get errors depending on their support.

// strip import attributes as we can process them ourselves
if (!isDynamicImport && attributeIndex > -1) {
str().remove(end + 1, expEnd)
}

On Firefox, it's a syntax error as it looks like they don't accept it yet https://bugzilla.mozilla.org/show_bug.cgi?id=1736059

On Chrome, the syntax is fine, but Vite is responding text/javascript, so this causes a different error:
https://stackblitz.com/edit/vitejs-vite-8nxtabzl?file=src%2Fmain.js

Failed to load module script: Expected a JSON module script but the server responded with a MIME type of "text/javascript". Strict MIME type checking is enforced for module scripts per HTML spec.

@hi-ogawa hi-ogawa added p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Dec 31, 2024
@JamesParrott
Copy link

Excellent. Thankyou very much :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

3 participants