parcel: Tree Shaking claims a library in an applications doesn't export a function
π bug report
Running --experimental-scope-hoisting will fail to bundle an app claiming that an library is not exporting a file. I checked node modules to see if this was the case, but itβs not. The function is being exported.
Error when bucklescript outputs es modules:

Error when bucklescript outputs commonjs:

Code the error refers to node_modules/react-infinite-calendar/es/Calendar/withDateSelection.js:
import _withState from 'recompose/withState';
import _withPropsOnChange from 'recompose/withPropsOnChange';
import _withProps from 'recompose/withProps';
import _compose from 'recompose/compose';
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import { withDefaultProps } from './';
import { sanitizeDate, withImmutableProps } from '../utils';
import format from 'date-fns/format';
import parse from 'date-fns/parse';
export var enhanceDay = _withPropsOnChange(['selected'], function (props) {
return {
isSelected: props.selected === props.date
};
});
var enhanceYear = _withPropsOnChange(['selected'], function (_ref) {
var selected = _ref.selected;
return {
selected: parse(selected)
};
});
// Enhancer to handle selecting and displaying a single date
var withDateSelection = _compose(withDefaultProps, withImmutableProps(function (_ref2) {
var DayComponent = _ref2.DayComponent,
onSelect = _ref2.onSelect,
setScrollDate = _ref2.setScrollDate,
YearsComponent = _ref2.YearsComponent;
return {
DayComponent: enhanceDay(DayComponent),
YearsComponent: enhanceYear(YearsComponent)
};
}), _withState('scrollDate', 'setScrollDate', function (props) {
return props.selected || new Date();
}), _withProps(function (_ref3) {
var _onSelect = _ref3.onSelect,
setScrollDate = _ref3.setScrollDate,
props = _objectWithoutProperties(_ref3, ['onSelect', 'setScrollDate']);
var selected = sanitizeDate(props.selected, props);
return {
passThrough: {
Day: {
onClick: _onSelect
},
Years: {
onSelect: function onSelect(year) {
return handleYearSelect(year, { onSelect: _onSelect, selected: selected, setScrollDate: setScrollDate });
}
}
},
selected: selected && format(selected, 'YYYY-MM-DD')
};
}));
export { withDateSelection };
function handleYearSelect(date, _ref4) {
var setScrollDate = _ref4.setScrollDate,
selected = _ref4.selected,
onSelect = _ref4.onSelect;
var newDate = parse(date);
onSelect(newDate);
setScrollDate(newDate);
}
π Configuration (.babelrc, package.json, cli command)
bsconfig:
{
"name": "...",
"bs-dependencies": [
"reason-react",
"bs-fetch",
"@glennsl/bs-json",
"bs-css",
"regql"
],
"ppx-flags": ["graphql_ppx/ppx"],
"reason": {
"react-jsx": 2
},
"refmt": 3,
"sources": ["vcomponents", "components", "pages", "styles"],
// "package-specs": ["es6-global"],
"bsc-flags": ["-bs-super-errors"]
}
package.json:
{
"name": "....",
"version": "0.1.0",
"description": "....",
"main": "index.js",
"private": true,
"dependencies": {
"@glennsl/bs-json": "^2.0.0",
"bs-css": "^6.7.0",
"bs-fetch": "^0.3.0",
"cross-env": "^5.2.0",
"graphql_ppx": "^0.2.3",
"prismjs": "^1.14.0",
"react-addons-css-transition-group": "^15.6.2",
"react-infinite-calendar": "^2.3.1",
"react-markdown": "^3.3.3",
"reason-react": "0.4.2",
"regql": "0.5.0-beta.10",
"serve": "^8.2.0",
"stijs": "^1.0.0",
"typeface-catamaran": "^0.0.54",
"typeface-montserrat": "^0.0.54"
},
"devDependencies": {
"bs-platform": "3.1.5",
"parcel-bundler": "1.9.0"
}
}
π€ Expected Behavior
Should bundle application
π― Current Behavior
fails to bundle application
π¦ Context
Trying to add tree shaking to existing applications using parcel. Hope this helps find bugs in the new scope hoisting feature.
π Your Environment
| Software | Version(s) |
|---|---|
| Parcel | 1.9.0 |
| Node | 10.4.0 |
| npm/Yarn | 1.7.0 |
| Operating System | macOS |
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 22 (8 by maintainers)
Commits related to this issue
- Omit ClientSettings import/export from entry module It's still unclear why, but the ClientSettings import/export here causes a problem in `parcel build` with the --experimental-scope-hoisting flag. ... — committed to openinsights/openinsights by jakewan 4 years ago
- Omit ClientSettings import/export from entry module It's still unclear why, but the ClientSettings import/export here causes a problem in `parcel build` with the --experimental-scope-hoisting flag. ... — committed to cbsinteractive/openinsights by jakewan 4 years ago
- Omit ClientSettings import/export from entry module It's still unclear why, but the ClientSettings import/export here causes a problem in `parcel build` with the --experimental-scope-hoisting flag. ... — committed to cbsinteractive/openinsights by jakewan 4 years ago
Can confirm, same issue here, using material-ui/core.
myFile.jsx:
import { Button, CircularProgress, Grid } from '@material-ui/core';index.es.js from material-ui/core:
fix is released in v1.9.1.