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

fix(legacy): import babel once #19152

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

hi-ogawa
Copy link
Collaborator

@hi-ogawa hi-ogawa commented Jan 7, 2025

Description

import('@babel/core') call is not deduped properly due to await and renderChunk is called in parallel for all chunks. Then weirdly, such duplicated import calls seem to be causing some issues with unbuild stub's interop and I was seeing a following error on main:

$ pnpm -C packages/plugin-legacy/ dev

$ pnpm -C playground/legacy build
...
x Build failed in 467ms
error during build:
[vite:legacy-post-process] babel.transform is not a function
    at Object.renderChunk (/home/hiroshi/code/others/vite/packages/plugin-legacy/src/index.ts:552:28)
    at transformChunk (file:///home/hiroshi/code/others/vite/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:18853:16)
    at file:///home/hiroshi/code/others/vite/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:18927:17
    at async Promise.all (index 8)
    at transformChunksAndGenerateContentHashes (file:///home/hiroshi/code/others/vite/node_modules/.pnpm/rollup@4.28.1/node_modules/rollup/dist/es/shared/node-entry.js:18922:5)
...

I'll try a reproduction on unbuild/jiti later. I couldn't get to the bottom of the issue, but I guess it's okay to have this change regardless. It would be nice if others can reproduce the same issue locally on main.

async function loadBabel() {
if (!babel) {
babel = await import('@babel/core')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a minimal repro. What I'm seeing locally was something like this:

    if (!!babel.transform) {
      console.log("[ok]")
    } else {
      console.log("[not ok]", babel)
    }
$ pnpm -C playground/legacy build
...
[not ok] [Object: null prototype] { default: {} }
[not ok] [Object: null prototype] { default: {} }
[not ok] [Object: null prototype] { default: {} }
[not ok] [Object: null prototype] { default: {} }
[not ok] [Object: null prototype] { default: {} }
[ok]
[ok]
[ok]

I tried JITI_DEBUG=true but still don't have any clue about where this behavior is coming from.

@hi-ogawa hi-ogawa marked this pull request as ready for review January 7, 2025 08:36
@patak-dev patak-dev merged commit 282496d into vitejs:main Jan 7, 2025
18 checks passed
@hi-ogawa hi-ogawa deleted the fix-legacy-babel-import-once branch January 12, 2025 01:13
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.

4 participants