rhysforyou/bs-enzyme

Fails to build with es6 modules

Closed this issue · 5 comments

When setting package-specs.module to "es6", I get the error TypeError: EnzymeAdapterReact is not a constructor.

Hmm i'll take a look

Seems like some typescript users have had this issue as well. enzymejs/enzyme#1284

I started looking at this, but Jest really hates dealing with ES Modules so I've had some trouble getting the test suite running on ES6 builds. Looking at the transpiled output though, I can see an issue:

import * as EnzymeAdapterReact from "enzyme-adapter-react-16";

Enzyme.configureEnzyme(new EnzymeAdapterReact());

It looks like despite the fact we're specifying the default export of enzyme-adapter-react-16 to be a function, it's still importing it as import * as Adapter from '...' instead of the correct import Adapter from '...'. This seems like a potential issue with BuckleScript but I'll see what I can do.

Okay this is a known issue in BuckleScript, see rescript-lang/rescript#2113

I'm keeping this PR open until that's fixed upstream.

What would be the issue if we changed typings to something like this?

[@bs.module "enzyme-adapter-react-16"] [@bs.new] external react_16_adapter : unit => adapter = "default";