https://github.com/stefcameron/rollup-2-41-4-bug-repro
https://github.com/stefcameron/rollup-2-41-4-bug-repro
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/stefcameron/rollup-2-41-4-bug-repro
- Owner: stefcameron
- Created: 2021-03-17T16:49:28.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-19T14:56:09.000Z (about 4 years ago)
- Last Synced: 2025-01-30T16:46:21.504Z (4 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rollup-2-41-4-bug-repro
Reported in [Rollup#3999](https://github.com/rollup/rollup/pull/3999), fixed in [Rollup#4001](https://github.com/rollup/rollup/pull/4001).
## Environment
- OS: macOS 11.2.3
- Node: 14.16.0
- npm: 7.6.1## Install
__USE NPM 7__ with this lock file.
`npm install` then `npm run build`.
## Reproduction
Run `npm run dev` and `npm run prod`.
The dev build outputs to `./dist/repro.dev.js` and the prod build to `./dist/repro.js`.
Compare both output files. Because `util.js` has `DEV && rtv.verify(color, cssHexColorTs);`, and `DEV=false` in the prod build, even though `typesets.js` doesn't "scope" its code with `DEV &&`, the `DEV &&` in `util.js` should result in the elimination of both `rtvjs` and `./typesets` modules from `util.js`, resulting in no `rtvjs` reference in the final bundle.
That was the behavior until `[email protected]`. But under `2.41.4`, the prod bundle looks like this:
```javascript
'use strict';var rtv = require('rtvjs');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}var rtv__namespace = /*#__PURE__*/_interopNamespace(rtv);
// in reality, this would be a more complex RTV.js typeset...
rtv__namespace.STRING;const hexToRgb = function (color) {
return color; // in reality, do the stuff to convert the color to 'rgb(...)'
};console.log(hexToRgb('#00ff00')); // #00ff00
```Notice that while the `cssHexColorTs` import has been eliminated, `typesets.js` is still pulled in, as is the reference to `rtvjs`, and we end-up with an orphaned expression (that used to be assigned to `cssHexColorTs` in `typesets.js`): `rtv__namespace.STRING;`
Now update `package.json` to reference `2.41.3` and run `npm run prod` again, and you'll get this in `./dist/repro.js`:
```javascript
'use strict';const hexToRgb = function (color) {
return color; // in reality, do the stuff to convert the color to 'rgb(...)'
};console.log(hexToRgb('#00ff00')); // #00ff00
```Which is what I'm expecting...