reason-react icon indicating copy to clipboard operation
reason-react copied to clipboard

ES6 output is broken for Rollup compilation/tree shaking

Open jsdf opened this issue 9 years ago • 4 comments

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.

jsdf avatar Jul 11 '17 05:07 jsdf

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.

chenglou avatar Jul 12 '17 06:07 chenglou

just tested with master and rollup is working again!

jsdf avatar Jul 12 '17 06:07 jsdf

This is released.

@jsdf how did you make rollup work with reactjs?

chenglou avatar Sep 07 '17 08:09 chenglou

@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

jsdf avatar Sep 07 '17 18:09 jsdf