[vite] warning: Top-level "this" will be replaced with undefined since this file is an ECMAScript module
See original GitHub issueDescribe 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.
[vite] hmr update /src/App.tsx
[vite] warning: Top-level "this" will be replaced with undefined since this file is an ECMAScript module
23 | lineNumber: 11,
24 | columnNumber: 9
25 | }, this), /*#__PURE__*/_jsxDEV("p", {
| ^
26 | children: "Hello Vite + React!"
27 | }, void 0, false, {
Plugin: vite:esbuild
File: /Users/naresh/projects/vite-esmbuild-issue/src/App.tsx
The issue has been discussed in the esmbuild repository here and closed: https://github.com/evanw/esbuild/issues/2328. They need to know exactly what flags vite is using to invoke esmbuild.
Reproduction
https://github.com/nareshbhatia/vite-esmbuild-issue
System Info
System:
OS: macOS 12.3.1
CPU: (4) x64 Intel(R) Core(TM) i5-7600K CPU @ 3.80GHz
Memory: 103.36 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
Yarn: 1.22.15 - ~/.yarn/bin/yarn
npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm
Watchman: 2022.03.21.00 - /usr/local/bin/watchman
Browsers:
Brave Browser: 96.1.32.115
Chrome: 102.0.5005.115
Safari: 15.4
npmPackages:
@vitejs/plugin-react: ^1.3.0 => 1.3.2
vite: ^2.9.9 => 2.9.12
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- 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 https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Reactions:9
- Comments:6 (1 by maintainers)
Top Results From Across the Web
this is changed to undefined with webpack + typescript + ...
json { "compilerOptions": { "module": "esnext" // other configuration ... } } I'm trying to pass this as a parameter in one of...
Read more >Troubleshooting - Vite
Vite cannot handle and does not support code that only runs on non-strict mode (sloppy mode). This is because Vite uses ESM and...
Read more >Output - webpack
The top-level output key contains a set of options instructing webpack on how and where it should output your bundles, assets, and anything...
Read more >vite warning top-level this will be replaced with ... - 掘金
vite warning top-level this will be replaced with undefined since this file is an ecmascript module技术、学习、经验文章掘金开发者社区搜索结果。
Read more >Options - Babel.js
npx babel --root-mode upward file.js # equivalent of passing the rootMode config ... would allow plugins and presets to decide that, since ES...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is happening because plugin-react uses
@babel/plugin-transform-react-jsx
to transform JSX.For a workaround, you could set
esbuild.logOverride
to omit the warning.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.