-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
enzyme_adapter_react_16_1.default is not a constructor #1284
Comments
See #1264 TypeScript doesn't yet create synthetic default imports like Babel does |
This is definitely a TypeScript bug. Closing in favor of #1264. |
thanks!! |
Based on the above answers, what i did to solve this is:
|
Incase anyone stumbles across this thread, I found the import * as Enzyme from 'enzyme';
import ReactSixteenAdapter from 'enzyme-adapter-react-16';
Enzyme.configure({ adapter: new ReactSixteenAdapter() }); |
@mattjegan this works for me!! thank you |
You shouldn't need |
It doesn't work for me |
TypeScript: |
@bazyliszek10000 in your case you should just |
@ljharb. With the current typing "@types/enzyme-adapter-react-16" (Type definitions for enzyme-adapter-react-16 1.0) you can not simply import the "Adapter". There are no export default type in the d.ts file, none of the exported types is called "Adapter". The solution is certainly not elegant, but it shows where the problem is. this:
|
@bazyliszek10000 then those types are incorrect; and you should file a bug upstream. |
this solution works with create react app and typescript, thanks @mattjegan |
You need to use the import like this: import Adapter from 'enzyme-adapter-react-16'; |
Another prerequisite for this to work is
The reason is described here: #1264 (comment) |
@InvictusMB THANK YOU! I've been at this all day... |
This was a critical piece of information in my journey to get enzyme to stop complaining. In |
Add "esModuleInterop": true it worked also for me. Thanks @bradgreens |
I also have such a problem |
my solution: |
@Myqilixiang you probably also need synthetic imports turned on. |
Works for me! |
import * as Enzyme from 'enzyme'; Enzyme.configure({ adapter: new Adapter() }); not working this |
You should never need |
Actually, the types look correct. Here's what I'm thinking, correct me if I'm wrong: The code is a commonJS style code that does: module.exports = ReactSixteenAdapter; Which means you shouldn't be able to default import anything. The built version isn't any different, so if in a commonjs module you'd import it, you'd say: const Adapter = require('enzyme-adapter-react-16'); So the types accordingly say: export = ReactSixteenAdapter; The only reason this works as you show in examples and in this thread, is because on the receiver end, you are using babel, and babel wraps legacy commonjs modules in |
@delanni that's all correct, however, with esModuleInterop and synthetic imports enabled in TS (which |
package.json
test file:
error:
The text was updated successfully, but these errors were encountered: