react-element-portal icon indicating copy to clipboard operation
react-element-portal copied to clipboard

`module` field in package.json should not point to fully uncompiled version

Open vitorbal opened this issue 7 years ago • 1 comments

The module field in package.json should point to a version of react-element-portal that has ES2015 module syntax but otherwise only syntax features that the target environments support.

Since react-element-portal uses syntax like object rest spread which not all target environments support, those should be compiled before publishing. More info on rationale here: https://github.com/rollup/rollup/wiki/pkg.module#wait-it-just-means-import-and-export--not-other-future-javascript-features

Most end-users that consume react-element-portal via module field will trip up on this bug, since it's very common to not compile modules from node_modules. Example error:

ERROR in ./node_modules/react-element-portal/src/ElementPortal.js
Module parse failed: /Code/zapier/node_modules/react-element-portal/src/ElementPortal.js Unexpected token (42:8)
You may need an appropriate loader to handle this file type.
|
|       const children = View ?
|         <View {...mapDomNodeToProps(node)} /> :
|         React.Children.only(this.props.children);
|
 @ ./node_modules/react-element-portal/src/index.js 1:0-44
[...]

While we're at it we might also consider switching the build step to use Rollup instead of plain babel.

vitorbal avatar Jan 05 '18 09:01 vitorbal

After this epic conversation: https://zapier.slack.com/archives/C0466L7SX/p1515145573000212, we decided:

  • main: bundle and transpile.
  • module: only transpile.
  • (optional) esnext: sources (http://2ality.com/2017/06/pkg-esnext.html)

ngryman avatar Jan 05 '18 11:01 ngryman