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

Uncaught SyntaxError: Unexpected token ? #14175

Closed
7 tasks done
igorMondu opened this issue Aug 22, 2023 · 5 comments
Closed
7 tasks done

Uncaught SyntaxError: Unexpected token ? #14175

igorMondu opened this issue Aug 22, 2023 · 5 comments
Labels
invalid This doesn't seem right

Comments

@igorMondu
Copy link

igorMondu commented Aug 22, 2023

Describe the bug

After upgrading from Vite 3.2.7 to 4.4.9, my production build is not working in old browsers, despite using vite legacy plugin. Reverting back to 3.2.7 fixes the issue, so the bug is somewhere in Vite v4.

The error I get when I try to load an app in Chrome 69 for example results in this error:

Uncaught SyntaxError: Unexpected token ?

Reproduction

https://github.com/paradox37/monorepo/tree/vite-legacy-bug

Steps to reproduce

  1. Run yarn install
  2. Run yarn build
  3. Run yarn preview
  4. Open the app in some old browser like Chrome 69 and observe DevTools Console

System Info

System:
    OS: macOS 13.2.1
    CPU: (8) arm64 Apple M1
    Memory: 110.33 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.16.0/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
  Browsers:
    Chrome: 116.0.5845.96
    Firefox: 116.0.3
    Firefox Developer Edition: 104.0
    Safari: 16.3

Used Package Manager

yarn

Logs

No response

Validations

@sapphi-red
Copy link
Member

This is by design, support for legacy browsers is a build-only feature. During dev mode, Vite doesn't transpile files.

@sapphi-red sapphi-red added invalid This doesn't seem right and removed pending triage labels Aug 23, 2023
@igorMondu
Copy link
Author

@sapphi-red Please re-open this. The build is not working in legacy browsers. I created a build and used vite preview to start it, then I opened it in Chrome 69 and got the error from the title, app crashed. And, if I downgrade to 3.2.7, it works. I see I wrote the wrong reproduction steps, I edited it.

@sapphi-red
Copy link
Member

sapphi-red commented Aug 25, 2023

@igorMondu
Copy link
Author

igorMondu commented Aug 25, 2023

@sapphi-red Thanks. But, that alone didn't help. I had to configure the plugin like this:

legacy({
  modernPolyfills: true,
  renderLegacyChunks: true,
})

For browser list, I put "supports es6-module".

I am wondering why I had to specify renderLegacyChunks: true. The documentation says for modernPolyfills: Enabling this option will generate a separate polyfills chunk for the modern build (targeting browsers with [native ESM support](https://caniuse.com/es6-module)).

Chrome 69 supports es6 modules, so I assumed I don't need to render legacy chunks.

@sapphi-red
Copy link
Member

I see. That part of the document was incorrect: #14233

@github-actions github-actions bot locked and limited conversation to collaborators Sep 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants