Skip to content

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

In review

Description

@hyunbinseo

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

Activity

  1. JamesParrott commented on Dec 30, 2024

    @JamesParrott
  2. hi-ogawa commented on Dec 31, 2024

    @hi-ogawa
    Contributor

    @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.

  3. changed the title [-]Dynamic import with `type: 'json'` causes syntax error[/-] [+]Dynamic import with `type: 'json'` causes syntax error on Firefox[/+] on Dec 31, 2024
  4. hi-ogawa commented on Dec 31, 2024

    @hi-ogawa
    Contributor

    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.
    
  5. added
    p3-minor-bug
    and removed on Dec 31, 2024
  6. JamesParrott commented on Jan 1, 2025

    @JamesParrott

    Excellent. Thankyou very much :)

  7. added a commit that references this issue on Mar 25, 2026
    49a68e6
  8. added this to the 8.5 milestone on Nov 11, 2026
  9. Johnx-w commented on Nov 11, 2026

    @Johnx-w

    I'd like to investigate this on current main and prepare a focused fix with regression coverage for dynamic JSON imports. I'll check the earlier attempts and verify the behavior in the browser before opening a PR.

  10. added theissue type on Nov 26, 2026
  11. self-assigned this
    on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

p3-minor-bug

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions