-
-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rollup fails to bundle memoizee correctly #121
Comments
Unfortunately while the above fix does prevent runtime errors, the bundle is still unusable As can be seen here in the bundle result, the if conditions are incorrect resulting in the function not to return a memoized value https://github.com/IamTheHttp/meomizee-with-rollup/blob/master/dist/index.js#L2020 |
@IamTheHttp great thanks for report. Still note it's not an issue in this package itself, but rather issue specific to rollup bundler, which may have some limitations, have you tried to report it over there? |
Hey @medikoo, I somewhat disagree that it's a rollup issue, but it's definitely related to rollup! This issue has two parts
The first bullet has been dealt by the rollup team and the addition of the The second bullet is a bit more complicated, consider this: // index.js
if (typeof window === 'object') require('./sideeffect'); // sideeffect.js
console.log('side effect');
// Completely tree shaken off, since it's not used in index.js anywhere
module.exports = {
some: 'property'
} The build output of rollup is: // dist/index.js
(function () {
'use strict';
console.log('side effect');
if (typeof window === 'object')
var src = {
};
var src$1 = src;
return src$1;
}()); This looks like an open (and closed) issue with rollup commonJS plugin rollup/rollup-plugin-commonjs#424 This doesn't look like it will be fixed by the plugin team. Alternatively, we can offer a pre-build package (by webpack or other bundlers) that will just work for anyone else (Since the problem is the bundling). As a library author myself, I think it's best to leave as little to chance as possible. |
@IamTheHttp this is a perfectly valid JS package, using just pure JS (no deprecated features), and plain CJS require syntax (without relying on any rarely used meta methods, which some bundlers may have problem with) If bundler cannot package such package well, it means there's a limitation on bundler side, and not in a package. I hardly see it can be otherwise. In this given case, if I understand correctly, some rollup specific optimizations when applied interfere with a package integrity so it breaks. It's a thing that should be discussed on Rollup ground and not here imo. Note that rollup doesn't constitute any industry standard here to be followed, instead it is expected to follow the standards which are followed by package as this one. |
Completely agreed, my only comment was about the package itself wanting to be accessible by others. Yes, this is probably an issue with rollup's commonjs plugin, however, the fix is so incredibly simple (and to my personal opinion, slightly improves the code quality) that I'm not sure why we wouldn't want to include it. Would you be open to a PR on this matter? |
@IamTheHttp feel free to open the PR. If change is minimal I think I'll be fine to take it. Still I'd like to also understand well why it cannot be addressed on Rollup side, |
This package cannot be correctly bundled by Rollup.
When attempting to bundle, rollup will freeze some objects, making the package fail at runtime
This is related to the freeze property of rollup (https://rollupjs.org/guide/en/#outputfreeze) which causes imports under certain conditions to be sealed (I'm not sure why they do that).
For anyone who's interested, a fix can be achieved by adding
output.freeze:false
to the rollup config:Repro: https://github.com/IamTheHttp/meomizee-with-rollup.git
The text was updated successfully, but these errors were encountered: