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

[Vite 3] Babel Bug #8868

Closed
7 tasks done
brillout opened this issue Jun 30, 2022 · 7 comments
Closed
7 tasks done

[Vite 3] Babel Bug #8868

brillout opened this issue Jun 30, 2022 · 7 comments
Labels
p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)

Comments

@brillout
Copy link
Contributor

Describe the bug

It seems that, in some scenarios, the babel plugin is trying to parse TypeScript code even though it's not configured to be able to parse TypeScript. Which breaks both dev and build.

The same code does work with Vite 2.

This is a blocker for building Vike Frameworks. (And, AFAICT there is no workaround for this bug, but I could be wrong.)

The bug reproduction is minimal but uses VikePress; let me know if you want more minimal reproduction that doesn't use VikePress.

This is the last bug for making Vite 3 + vite-plugin-ssr green again 🎉.

(I'm curious what the reason is for using Babel since esbuild supports JSX.)

Reproduction

https://github.com/brillout/vite-3-babel-bug

System Info

System:
    OS: Linux 5.10 Debian GNU/Linux 10 (buster) 10 (buster)
    CPU: (2) x64 Intel(R) Celeron(R) N4020 CPU @ 1.10GHz
    Memory: 570.86 MB / 2.71 GB
    Container: Yes
    Shell: 5.0.3 - /bin/bash
  Binaries:
    Node: 18.0.0 - ~/.config/nvm/versions/node/v18.0.0/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.6.0 - ~/.config/nvm/versions/node/v18.0.0/bin/npm
  Browsers:
    Firefox: 97.0.1
  npmPackages:
    vite: ^2.8.4 => 3.0.0-beta.5

Used Package Manager

pnpm

Logs

No response

Validations

@sapphi-red
Copy link
Member

It works with Vite 2.9.13+ plugin-react v2.0.0-alpha.2
It does not work with Vite 2.9.13/3.0.0-beta.3 + plugin-react v2.0.0-alpha.3.

I feel #5313 is affecting this.
Would it work if jsxRuntime: 'classic' is set?

(I'm curious what the reason is for using Babel since esbuild supports JSX.)

AFAIK it is because fast-refresh and automatic runtime is not supported by esbuild.

@brillout
Copy link
Contributor Author

brillout commented Jul 1, 2022

Would it work if jsxRuntime: 'classic' is set?

That fixes the error and makes the client-side build work, but the server-side build fails with:

vite v3.0.0-beta.5 building SSR bundle for production...
✓ 56 modules transformed.
'escapeInject' is not exported by node_modules/.pnpm/[email protected][email protected]/node_modules/vite-plugin-ssr/dist/cjs/node/index.js, imported by node_modules/.pnpm/[email protected]_biqbaboplfbrettd7655fr4n2y/node_modules/vikepress/src/algolia/DocSearch.ts
file: /home/romuuu/tmp/vite-3-babel-bug/node_modules/.pnpm/[email protected]_biqbaboplfbrettd7655fr4n2y/node_modules/vikepress/src/algolia/DocSearch.ts:1:0
1: import { escapeInject } from 'vite-plugin-ssr'
   ^
2: import { PageContextResolved } from '../config/resolvePageContext'
file:///home/romuuu/tmp/vite-3-babel-bug/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:1858
        base = Object.assign(new Error(base.message), base);
                             ^

Error: 'escapeInject' is not exported by node_modules/.pnpm/[email protected][email protected]/node_modules/vite-plugin-ssr/dist/cjs/node/index.js, imported by node_modules/.pnpm/[email protected]_biqbaboplfbrettd7655fr4n2y/node_modules/vikepress/src/algolia/DocSearch.ts

You can reproduce by setting react({ jsxRuntime: 'classic'}) at vite-3-babel-bug/node_modules/.pnpm/[email protected]_biqbaboplfbrettd7655fr4n2y/node_modules/vikepress/vite.config.ts.

Shall I open a new bug report for this?

@sapphi-red
Copy link
Member

sapphi-red commented Jul 1, 2022

@brillout Yes, I guess there is a different bug. Would you create it?

brillout added a commit to brillout/docpress that referenced this issue Jul 1, 2022
brillout added a commit to brillout/docpress that referenced this issue Jul 1, 2022
@brillout
Copy link
Contributor Author

brillout commented Jul 1, 2022

Done: #8880. Let me know if there is anything I can do to help.

@brillout
Copy link
Contributor Author

brillout commented Jul 1, 2022

In case you are wondering why vikepress includes .ts, .css, and .svg files: that's because Node.js cannot handle import './someStyles.css' nor import emojiUrl from './someEmoji.svg', which means that vikepress cannot be externalized. That's why vikepress publishes its source files to npm.

@brillout
Copy link
Contributor Author

brillout commented Jul 6, 2022

This bug also happens with 3.0.0-beta.7. The reproduction is updated and now uses 3.0.0-beta.7.

@brillout
Copy link
Contributor Author

brillout commented Jul 8, 2022

Fixed in beta.9 🎉

@brillout brillout closed this as completed Jul 8, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jul 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
Development

No branches or pull requests

2 participants