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

Exported class name (from a .ts file) is prefixed with an unwanted underscore (in the generated file) #16642

Closed
7 tasks done
cristian-spiescu opened this issue May 9, 2024 · 1 comment

Comments

@cristian-spiescu
Copy link

cristian-spiescu commented May 9, 2024

Describe the bug

I have in my project a file such as:

export class RecordPlayModal extends React.Component<Props, State> {
  static errorMessageLibIncludedMultipleTimes = false;
  ...
  render() {
    ...
   {RecordPlayModal.errorMessageLibIncludedMultipleTimes && <Message error> ...

Because of the last line, the generated file looks like this (notice the prefix/underscore):

class _RecordPlayModal4 extends React.Component {
  static errorMessageLibIncludedMultipleTimes = false;
  ...

If I comment the offending line, the file is generated w/ its normal name.

Of course, because this renaming, I have a further runtime error saying:

.../RecordPlayModal.tsx?t=1715249292267' does not provide an export named 'RecordPlayModal'

I was able to workaround by changing the code so:

class RecordPlayModalInternal {
...
}

export const RecordPlayModal = RecordPlayModalInternal;

Reproduction

Unfortunately I am not able to provide a minimal projects that reproduces the issue. Even worse, the error I'm complaining about appeared after moving code from one vite project to another vite project.

System Info

Note: I'm using a mono-repo architecture. I ran the command in the top of the repo

  System:
    OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
    CPU: (16) x64 AMD Ryzen 7 6800H with Radeon Graphics
    Memory: 6.47 GB / 15.22 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 20.5.1 - /usr/bin/node
    Yarn: 1.22.19 - ~/node_modules/.bin/yarn
    npm: 9.8.0 - /usr/bin/npm
  npmPackages:
    @vitejs/plugin-react: ^2.1.0 => 2.2.0 
    vite: ^3.1.0 => 3.2.10 

Used Package Manager

yarn

Logs

No response

Validations

Copy link

Hello @cristian-spiescu. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants