-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
TypeError: Class constructor App cannot be invoked without 'new' #1751
Comments
I just noticed that if as
instead of the one of It must be something in the |
While unrelated to your question, I am a bit confused about how you expect |
Yes I actually eject it, but I could reproduce the same problem without ejecting it and I think it's enough to proof that there's something wrong in the |
The problem here is likely that While we could fix it by always applying the class transform, we gotta move to real ES classes at some point, so it’s still a time bomb. I would just suggest avoiding libraries that try to inherit from your classes, or bringing it up with those libraries to not use the Babel I hope this helps! |
I'd have preferred to get a fix here, because this project is already very limiting and adding this additional limitation seems simply to much. Also, it doesn't make sense that the same code will work in browser but not during tests, within the same project. But I guess it's up to you. |
What kind of fix are you proposing? It is not very clear to me. As I said, any kind of fix would be a time bomb because it would still stop working as soon as you want to switch to native classes in the browser (which you'll probably want to in a couple of years). |
What additional limitation are you referring to? CSS modules don’t work out of the box anyway. If you eject, you might as well make your own Babel config that enables Babel class transform on Node too. But keep in mind it will make your tests slower, and will keep your app tied to Babel class transform. Because even if you want to disable it in the future, you’d bump into the same issue. This is not really our issue, but rather Babel output being incompatible with the native classes. You can bring it up in |
Also, now that I think of it, I don't really see why you'd want to apply jest.mock('react-css-modules', () => Component => Component); This would probably circumvent the problem. |
It won’t be exact same code anyway. The environment is different, the VM is different, etc. What you describe sounds like integration testing, and I fully agree you should add integration tests (e.g. Selemium) to your app.
I’m not sure if you read the linked issue, but it’s not extending native classes that’s broken per se, but extending them using Babel transform. If |
This really is an issue with |
Okay I see your point, thank you. |
I'll probably say something stupid, but why not removing react-css-modules from create-react-app or make it opt-in? I'm not using CSS in JS, but aren't there any other solution? On my end, i'm disappointed to not being able to extend ES6 classe because of a plugin I don't use. One of the benefits of create-react-app is that things should go smooth. A buggy dependency impacts the quality of the whole project, and I don't think you should let that happen (nevertheless, it's an edge case) |
I don't understand. Create React App does not include this plugin. If you experience an error with this message please provide an example reproducing it. |
@gaearon My apologizes, I didn't read properly the first comment. I experience the same problem, indeed, but found out it's because of React Router. |
If you are reporting a bug, please fill in below. Otherwise feel free to remove this template entirely.
Can you reproduce the problem with latest npm?
Yes
Yes
Description
Trying to use React CSS Modules inside
create-react-app
, only during Jest tests, leads to:Expected behavior
The code should work fine, like it happens when I use
yarn start
Actual behavior
I get the error reported above.
Environment
Run these commands in the project folder and fill in their results:
npm ls react-scripts
(if you haven’t ejected): 0.9.4node -v
: 7.5.0npm -v
: 4.1.2Then, specify:
Reproducible Demo
This is a super simple repository created with create-react-app:
https://github.com/FezVrasta/create-react-app-css-modules-bug
Just run
yarn test
to see the error.The only edited file is:
https://github.com/FezVrasta/create-react-app-css-modules-bug/blob/master/src/App.js
Where I added
react-css-modules
Note that this error happens only when I use
create-react-app
as base, in other repositories setup from scratch it works fine, but I can't understand why.The text was updated successfully, but these errors were encountered: