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

chore(deps): update to esbuild 0.14.14, with patched dist #6639

Merged
merged 4 commits into from
Jan 30, 2022

Conversation

patak-dev
Copy link
Member

Description

Implement an idea from @antfu, using esbuild 0.14.14 and adding the commonjs require hack after bundling instead of before it.

Additional context

This allows us to continue using esbuild to bundle plugin-vue and plugin-react, but I think there are new bugs surfacing because of the new esbuild version in plugin-react

esbuild 0.14.4 introduced a breaking change.

  • here we moved from 0.13 to a fixed 0.14.3: #5861
  • @Niputi tried to update the plugins build process from esbuild to rollup, but CI is failing for a React test case #6329
  • @dominikg proposed to fix esbuild only for building the plugins, #6405 (so two esbuild version, but only during build)
  • Anthony proposed to use latest esbuild and manually add the cjs hack. This PR implements this approach for testing

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@patak-dev
Copy link
Member Author

I tested this more, and the patched dist looks good to me. The plugin is properly imported in cjs and esm contexts. The issue is also the same as when compiling with rollup.

The only failing test is playground/react-emotion, see https://github.com/vitejs/vite/runs/4950179776?check_suite_focus=true#step:10:273

[BABEL] /home/runner/work/vite/vite/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/react-switch/dist/react-switch.min.js: .default is not a valid Plugin property

This issue is gone when using jsxRuntime: 'classic' for this playground. When using it, the issue is gone but there is another fail, but it isn't a regression: this playground fails in the same way when using 'classic' in main.

@aleclarson I think this is pointing to an issue on react-emotion side, and not in Vite or plugin-react. I don't understand why it doesn't surface with esbuild 0.14.3 though. Do you have some ideas here?

@patak-dev
Copy link
Member Author

Updated the react-emotion to use jsxRuntime: 'classic' and skipped the test that is failing also in main for classic. CI is green with these changes.

We could move forward with this PR (or the rollup based one #6329), so we unblock the release of Vite 2.8. If we do so, we shouldn't release @vitejs/plugin-react until the react-emotion test is properly fixed.

@haoqunjiang
Copy link
Member

I think I found the culprit

@haoqunjiang
Copy link
Member

haoqunjiang commented Jan 28, 2022

plugins: [await babelRestoreJSX]
This line.

Note this promise is an async import:

babelRestoreJSX ||= import('./babel-restore-jsx')

So, adding a .default to the result of the async import would fix the issue.

@patak-dev patak-dev requested a review from haoqunjiang January 28, 2022 15:15
@patak-dev patak-dev merged commit a4895ed into main Jan 30, 2022
@patak-dev patak-dev deleted the chore/esbuild-patched branch January 30, 2022 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants