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

[plugin-terser] The worker approach to running Terser breaks many valid Terser options #1781

Open
justinfagnani opened this issue Oct 3, 2024 · 3 comments

Comments

@justinfagnani
Copy link

Expected Behavior

All valid Terser options are supported. For this reproduction, the Terser nth_identifier option works.

Actual Behavior

An exception during build because only some of the code for the nth_identifier option is serialized. Other things seem to break from serializing the options, like nameCache updates.

Additional Information

The offending line that shows up in stack traces is here:

const options = eval2(`(${data.options})`);

But, the technique of taking options in one realm and serializing them to another, like a worker, is just not generally workable. Not all Terser options will be serializable. Functions are an obvious case, but I've had other cases of objects with prototypes, etc., breaking too.

@justinfagnani justinfagnani changed the title [plugin-terser] The worker approach to running Terse breaks many valid Terser options [plugin-terser] The worker approach to running Terser breaks many valid Terser options Oct 3, 2024
@midnight-wonderer
Copy link

Wow, that's how nameCache doesn't work.

It seems to be officially supported according to the type definition.

nameCache?: Options['nameCache'];

I thought there was something wrong with my setup.
Do you have a workaround?

@midnight-wonderer
Copy link

Found one!

Basically, nameCache is supported. However, the issue lies in the parallel worker execution.
On each successful terser execution, the nameCache output gets merged into the central cache object.

The problem arises when the same name appears on multiple files that are being processed in parallel. Each mangles independently, sending out conflicting output cache.

The workaround is setting maxWorkers to 1.

@justinfagnani
Copy link
Author

That workaround won't work for nth_identifier unfortunately, since it can be a function and functions can't be reliably serialized.

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

No branches or pull requests

2 participants