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:react-swc plugin conflict with vite-plugin-conditional-compile #8

Open
f4-miyata opened this issue Jul 10, 2024 · 1 comment
Open

Comments

@f4-miyata
Copy link

Description:

When using vite-plugin-conditional-compile in a Vite project with the vite:react-swc plugin,
an error occurs during the build process. The vite:react-swc plugin throws a syntax error.

Environment:

  • vite: "^5.2.6"
  • vite-plugin-conditional-compile: "^1.4.5"
  • @vitejs/plugin-react-swc": "^3.6.0"
  • Node: "20.10.0"
  • pnpm: "8.15.5"
  • OS: macOS 13.6.7

Steps to Reproduce:

  1. Install vite-plugin-conditional-compile and vite-plugin-react-swc.
    2.Use conditional compilation in a React component
import React from 'react';
import { Route } from 'react-router-dom';
import { Page } from '@debug/pages/Page';

const AppRoutes = () => {
  return (
    <>
      {/* #if [DEV] */}
      <Route path="/Page" element={<Page />} />
      {/* #endif */}

      <Route path="/Error" element={<ErrorPage />} />
    </>
  );
};

export default AppRoutes;
  1. Run the Vite development server or build the project.

  2. The following syntax error occurs during the build process:

Plugin: vite:react-swc
File: /path/to/project/src/app/AppRoutes.tsx:12:1

SyntaxError: Unexpected token (15:0)
  13 |
  14 |
> 15 | }
     | ^
  16 | </Route>
  17 |
  18 | <Route path="/Error" element={<ErrorPage />} />
@f4-miyata
Copy link
Author

f4-miyata commented Jul 12, 2024

@LZS911
I tried the following code, then it works as expected:

{
  // #if [DEV]
  <Route path="/Page" element={<Page />} />
  // #endif
}

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

No branches or pull requests

1 participant