You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using @vitejs/plugin-legacy to target Chrome >= 38, including polyfills so I expect the app work properly in Chrome 38. However, when I run the built app on that browser an error is displayed in the console: "Unhandled promise rejection TypeError: @@toPrimitive must return a primitive value".
In my app, I'm using Axios. One of its classes (AxiosHeaders) defines a [Symbol.iterator] property. So, when Babel transpiles this class, it defines this property calling Symbol.iterator[Symbol.toPrimitive]('string'). This call returns an object, not a primitive value, so the error is thrown.
As you can see in the reproduction, it will happen with any class that defines [Symbol.iterator] (and probably any other property identified for well known Symbol ([Symbol.toPrimitive] for example))
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Describe the bug
I'm using
@vitejs/plugin-legacy
to target Chrome >= 38, including polyfills so I expect the app work properly in Chrome 38. However, when I run the built app on that browser an error is displayed in the console: "Unhandled promise rejection TypeError: @@toPrimitive must return a primitive value".In my app, I'm using Axios. One of its classes (
AxiosHeaders
) defines a[Symbol.iterator]
property. So, when Babel transpiles this class, it defines this property callingSymbol.iterator[Symbol.toPrimitive]('string')
. This call returns an object, not a primitive value, so the error is thrown.As you can see in the reproduction, it will happen with any class that defines [Symbol.iterator] (and probably any other property identified for well known Symbol ([Symbol.toPrimitive] for example))
This makes Vite unusable to target those browsers. (Chrome 38 is important because it's the version of the engine running under SmartTVs LG with webOS 3.x, see https://webostv.developer.lge.com/develop/specifications/web-api-and-web-engine#web-engine)
The same code, built with Webpack works fine.
This bug was initially reported on #12844 but it didn't provide a reproduction
Reproduction
https://github.com/cdatehortuab/vite-issue-plugin-legacy
Steps to reproduce
npm install
npm run build
npx vite preview
System Info
Used Package Manager
npm
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: