-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[vite] warning: Top-level "this" will be replaced with undefined since this file is an ECMAScript module #8644
Comments
This is happening because plugin-react uses For a workaround, you could set import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
esbuild: {
logOverride: { 'this-is-undefined-in-esm': 'silent' }
}
}) |
Yup, That worked 👍 @sapphi-red |
So... The solution above still doesn't work. Choosing to ignore it at the moment. More Context: When the app rebuilds and an error is encountered, the warnings re-appear. |
Thanks |
Worked for me. Thanks! |
My coworker comes up with this work around and it works. He adds this workaround and put them along side the rest of the configuration. export default defineConfig({
plugins: [
process.env.MODE !== 'production'
? react({
jsxRuntime: 'classic',
})
: react(),
WindiCSS(),
],
... other properties
}); |
Describe the bug
Running a React app with Vite has started producing the above error since version change of esmbuild from v0.14.44 to v0.14.45. This error occurs wherever the React app is using an arrow function. My reproduction below has created a fresh Vite app and only changed the App component from a function to a function expression using an arrow function and this error starts appearing.
The issue has been discussed in the esmbuild repository here and closed: evanw/esbuild#2328. They need to know exactly what flags vite is using to invoke esmbuild.
Reproduction
https://github.com/nareshbhatia/vite-esmbuild-issue
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: