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

Error when using block comments in JSX: "repeat count must be non-negative" #272

Closed
7 tasks done
sidola opened this issue Dec 7, 2023 · 2 comments
Closed
7 tasks done
Labels
bug Something isn't working dependencies

Comments

@sidola
Copy link

sidola commented Dec 7, 2023

Describe the bug

I'm encountering a bug on ^4.2.0 where if I'm using a block comment in JSX and have an additional block comment somewhere below it in the code babel blows up with the error "repeat count must be non-negative".

Minimal repro seems to be:

export const App = () => {
  return (
    /* 
    This comment
    */
    <div>{'Hello world'}</div>
  );
};

/**
 * Plus this comment
 */
function someFunc() {
  // ...
}

I assume the culprit is some upstream babel dependency but I'm unsure exactly where to report it.

Reproduction

https://stackblitz.com/edit/vitejs-vite-fjadpp?file=index.html,src%2FApp.tsx,src%2Fmain.tsx&terminal=dev

Steps to reproduce

Open the link and try running the app, error should appear in the console.

System Info

System:
  OS: Linux 5.0 undefined
  CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Memory: 0 Bytes / 0 Bytes
  Shell: 1.0 - /bin/jsh
Binaries:
  Node: 18.18.0 - /usr/local/bin/node
  Yarn: 1.22.19 - /usr/local/bin/yarn
  npm: 9.4.2 - /usr/local/bin/npm
  pnpm: 8.10.5 - /usr/local/bin/pnpm
npmPackages:
  @vitejs/plugin-react: ^4.2.0 => 4.2.1 
  vite: ^5.0.4 => 5.0.6

Used Package Manager

npm

Logs

11:10:25 [vite] Internal server error: /home/projects/vitejs-vite-fjadpp/src/App.tsx: repeat count must be non-negative
  Plugin: vite:react-babel
  File: /home/projects/vitejs-vite-fjadpp/src/App.tsx

Validations

@ArnaudBarre
Copy link
Member

This is a bug in Babel when using retainLines that was added recently to fix JSX source locations.
Thanks for making a small reproduction, I've reported it here: babel/babel#16165

To work around you can:

  • Patch @babel/code to not repeat 0 times if ident < 0
  • Patch this plugin and disable the use of retainLines
  • Try out the SWC plugin if you don't depend on something specific to Babel
  • Avoid multi lines comments inside parentheses (maybe?, not exactly sure what triggers it)

@ArnaudBarre ArnaudBarre added bug Something isn't working dependencies and removed pending triage labels Dec 10, 2023
@ArnaudBarre
Copy link
Member

This should be fixed now!

@github-actions github-actions bot locked and limited conversation to collaborators Jan 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working dependencies
Projects
None yet
Development

No branches or pull requests

2 participants