Skip to content
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

commonjs: requireReturnsDefault: "preferred" yields unstable results #869

Closed
thorn0 opened this issue Apr 26, 2021 · 3 comments · Fixed by #871
Closed

commonjs: requireReturnsDefault: "preferred" yields unstable results #869

thorn0 opened this issue Apr 26, 2021 · 3 comments · Fixed by #871

Comments

@thorn0
Copy link
Contributor

thorn0 commented Apr 26, 2021

Expected Behavior

Calling Rollup multiple times with the same settings should lead to the same output.

Actual Behavior

Only the first time the output is correct and as expected. Subsequent outputs are incorrect and different from the first one.

Additional Information

for (let i = 0; i <= 3; i++) {
  const result = await rollup({
    input: "input.js",
    plugins: [commonjs({ requireReturnsDefault: "preferred" })],
  });

  await result.write({ file: `output/result${i}.mjs` });
}

First output:

var numbers = [1, 2, 3, 4, 5, 6];

console.log(numbers);

var input = {

};

export default input; 

Subsequent output:

var constants = [1, 2, 3, 4, 5, 6];

var constants$1 = /*#__PURE__*/Object.freeze({
	__proto__: null,
	'default': constants
});

console.log(constants$1);

var input = {

};

export default input; 

This works as expected:

const plugins = [commonjs({ requireReturnsDefault: "preferred" })];

for (let i = 0; i <= 3; i++) {
  const result = await rollup({
    input: "input.js",
    plugins,
  });

  await result.write({ file: `output/result${i}.mjs` });
}
@thorn0
Copy link
Contributor Author

thorn0 commented Apr 26, 2021

The reason is likely this variable shared between instances:

const isCjsPromises = new Map();

@guybedford
Copy link
Contributor

Thanks for spotting this bug. Would you be interested in working on a PR here?

@thorn0
Copy link
Contributor Author

thorn0 commented Apr 26, 2021

It blocks a release of a package I maintain, so potentially - yes. But it can take some time. If somebody can fix this more quickly, do it, don't wait for me. ;)

upd: Found #658 and checked if it fixes this issue. It doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants