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
2.55.0 regression - Unable to bundle semver@7
#4195
Comments
If
Curiously if you take the good run above and pipe its no-treeshake rollup output through rollup again to treeshake it, it still will work:
So it's only a tree shaking problem if done within rollup on the initial run. The rollup regression was introduced in 9a23190. If this patch is applied: --- a/src/ast/variables/ExportDefaultVariable.ts
+++ b/src/ast/variables/ExportDefaultVariable.ts
@@ -53,9 +53,8 @@ export default class ExportDefaultVariable extends LocalVariable {
getDirectOriginalVariable(): Variable | null {
return this.originalId &&
(this.hasId ||
!(
- this.originalId.isPossibleTDZ() ||
this.originalId.variable.isReassigned ||
this.originalId.variable instanceof UndefinedVariable ||
// this avoids a circular dependency
'syntheticNamespace' in this.originalId.variable then #4195 will work once again with treeshake enabled:
However, test/function/samples/default-export-before-declaration will now fail. |
Unpatched
|
Which again leads me to think we should add a flag to disable the TDZ detection logic, or at least the part that deals with TDZ access errors, because without it, Rollup accidentally paints over issues in the commonjs plugin. And to avoid "regressions", it should probably be disabled until we either fixed the commonjs plugin sufficiently or reach the next major version. |
I thought it was semver problem. :) resolved: |
TDZ and its |
I understand your point but people are currently raising issues as regressions because we removed the papering. Most people have tree-shaking enabled. There is virtually zero benefit to nearly all users to have proper TDZ errors. Sure, it is not correct, but most people prefer working but slightly incorrect code over non-working code. |
Just want to make sure we're on the same page. The term "TDZ" is normally associated with ES6 style If we applied the following patch to latest master to simulate the disabling of TDZ by rollup by default: --- a/src/ast/nodes/Identifier.ts
+++ b/src/ast/nodes/Identifier.ts
@@ -178,2 +178,4 @@ export default class Identifier extends NodeBase implements PatternNode {
isPossibleTDZ(): boolean {
+ return false;
+
// return cached value to avoid issues with the next tree-shaking pass then the following ES5 code would fail:
Is this the default Rollup 2 behavior being proposed as a stop-gap fix? |
fwiw, the version of rollup before TDZ logic was introduced does not work with the latest version of
expected:
actual:
|
I was very much under the impression that it is the const/let behaviour that is causing issues, and only that I want to put behind a toggle. The var behaviour is crucial in preventing bugs and should of course stay. |
As far as I know, the few recent commonjs bug reports all involve |
There are many test examples of its use, but I couldn't get it to work with non-trivial npm packages with circular
If anyone is able to configure |
You can import one by one as workaround: import maxSatisfying from "semver/ranges/max-satisfying";
import minSatisfying from "semver/ranges/min-satisfying";
import coerce from "semver/functions/coerce"; |
I've created a new plugin that can be used instead of It can be downloaded from here: rollup-plugin-strict-cjs-0.1.0.tar.gz and installed with:
The single source file for the plugin is included in the tarball package and could be used in user projects directly without the need for a package. This plugin strives to be compatible with NodeJS cjs behavior. When mixed esm/cjs modules are used it tries to mimic esbuild's behavior. The generated bundled cjs code does not rely on treeshaking and works equally well with treeshaking disabled. The plugin options are similar to Here's a simple example of a commonjs circular dependency, also known as a
Expected result:
which matches the expected NodeJS output. For the real world projects I've tried, The plugin was tested on rollup itself by successfully building and running diff --git a/build-plugins/conditional-fsevents-import.ts b/build-plugins/conditional-fsevents-import.ts
index 5378269..a98feff 100644
--- a/build-plugins/conditional-fsevents-import.ts
+++ b/build-plugins/conditional-fsevents-import.ts
@@ -17 +17 @@ export default function conditionalFsEventsImport(): Plugin {
- if (id.endsWith('fsevents-handler.js')) {
+ if (id.endsWith('fsevents-handler.js?cjs')) {
diff --git a/rollup.config.ts b/rollup.config.ts
index 0f4061d..ab7914d 100644
--- a/rollup.config.ts
+++ b/rollup.config.ts
@@ -4 +4 @@ import alias from '@rollup/plugin-alias';
-import commonjs from '@rollup/plugin-commonjs';
+import commonjs from 'rollup-plugin-strict-cjs'; An implementation detail bleeds through in the rollup build case, namely the |
@guybedford this might be worth a look |
@kzc thanks for diving into it and proposing a fix. I looked at what you are saying in rollup/plugins#988, I find that I have a similar error but with another rollup plugin:
This is I believe coming from this line: https://github.com/rollup/rollup-plugin-node-resolve/blob/master/src/index.js#L11. I am not sure I understand what's happening all in all so if you have any idea I am happy to hear them. I think there is a reason for me to use that old plugin rather than the newer |
Cannot reproduce with latest versions of all packages:
|
@nicolo-ribaudo We are finalizing a new version of the commonjs plugin in rollup/plugins#1038. It is pre-published as |
@lukastaegert |
Rollup Version
2.55.0
Operating System (or Browser)
Ubuntu 21.04, but it probably doesn't matter
Node Version (if applicable)
16.3.0
Link To Reproduction
https://github.com/nicolo-ribaudo/rollup-2.55-bug-semver-7
Expected Behaviour
Rollup 2.55 should produce the same valid code as produced by Rollup 2.54
Actual Behaviour
Due to a cyclic dependency, it emits some code that uses a variable before that it's initialized.
@rollup/plugin-commonjs@19
, this bug disappears. However, a minor version of Rollup shouldn't force me to update a major version of a plugin (also,@rollup/plugin-commonjs@19
isn't working for me: rollup/plugins#962).The text was updated successfully, but these errors were encountered: