Skip to content

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

Merged
patak-cat merged 4 commits into
mainfrom
chore/esbuild-patched
Jan 30, 2022
Merged

chore(deps): update to esbuild 0.14.14, with patched dist#6639
patak-cat merged 4 commits into
mainfrom
chore/esbuild-patched

Conversation

@patak-cat
Copy link
Copy Markdown
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

Comment thread packages/plugin-react/src/index.ts
Comment thread scripts/patchEsbuildDist.ts Outdated
@patak-cat
Copy link
Copy Markdown
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/react-switch@6.0.0_react-dom@17.0.2+react@17.0.2/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-cat
Copy link
Copy Markdown
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
Copy Markdown
Member

I think I found the culprit

@haoqunjiang
Copy link
Copy Markdown
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-cat patak-cat requested a review from haoqunjiang January 28, 2022 15:15
@patak-cat patak-cat merged commit a4895ed into main Jan 30, 2022
@patak-cat patak-cat 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