ES6 output is broken for Rollup compilation/tree shaking
When trying to compile Reason React with Rollup, the error
Error: Cannot call a namespace ('CreateClassInternalHack')
is thrown when compiling reason-react/lib/es6/src/reasonReact.js
import * as CreateClassInternalHack from "create-react-class";
is the problem, because trying to import the module's exports with import *, but create-react-class is not a real ES6 module, and only exports a function. When CreateClassInternalHack is called as a function, that's invalid as the result of import * should be an object.
Instead the import should ideally just import the default export:
import CreateClassInternalHack from "create-react-class";
However it might be difficult to get BuckleScript to produce this output. An alternative might be to define a wrapper JS module for create-react-class which exports this function in a way which is compatible with the import that BuckleScript produces.
I've pushed https://github.com/reasonml/reason-react/commit/2c9068a1431c96e19e4327f2023e8b726c87ebaa; feel free to iterate on master! Will close this issue during the next release.
Crazy diff btw. The artifacts diff shows we've got some level of guarantee that this isn't breaking callers.
just tested with master and rollup is working again!
This is released.
@jsdf how did you make rollup work with reactjs?
@chenglou here is the setup I used: https://github.com/reasonml-community/reason-react-hacker-news/blob/master/webpack.config.js#L48-L53
I've just updated the repo and rollup seems to be working. You can try it out by building with ROLLUP=1 yarn build