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

Error thrown by Terser is not handled #17

Open
Francois-Esquire opened this issue Jan 18, 2023 · 6 comments
Open

Error thrown by Terser is not handled #17

Francois-Esquire opened this issue Jan 18, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@Francois-Esquire
Copy link

Hi there, we've encountered a problem when the minified source does not output code. Found on this line here, the error from terser v4.8.0 is not handled, but rather we see an error where the length of the minified code has no length (found here).

[!] (plugin size-snapshot) TypeError: Cannot read properties of undefined (reading 'length')

Wondering if the solution below would be welcomed to throw this error (pseudo-code):

const { code: minified, error: minifiedError } = minify(source);

if (minifiedError) {
  throw minifiedError;
}

Happy to open up a pull request to patch.

@brodybits brodybits added the bug Something isn't working label Jan 18, 2023
@brodybits
Copy link
Owner

Thanks! Yes a patch would be welcome, but unfortunately I cannot guarantee when I may have a chance to understand and review it. And adding a test case would be especially helpful.

I think this plugin was made to work with the original rollup-plugin-terser, looks like newer @rollup/plugin-terser is now using terser v5.

@brodybits
Copy link
Owner

Possibly related: TrySound#61

Most important for me would be a simple reproduction that we can keep in a test case.

brodybits added a commit that referenced this issue Jan 22, 2023
Improvement with better error handling was proposed in:
- #17

but a reproduction is needed to add a test case, see
- #19
@Francois-Esquire
Copy link
Author

Thanks for getting back so promptly @brodybits and apologies for the delay in response! Really appreciate you updating with a way to know if Terser is failing, since it on our path to fixing build errors we are seeing in our projects. I talked to my team and we have time and I am happy to write a test case once we sort out a way of replicating. We are still looking into the reason it is failing, but you can see the failure here.

@brodybits
Copy link
Owner

you can see the failure here.

zendeskgarden/react-containers#493 ... namely this commit: zendeskgarden/react-containers@1cbd6f6

I will try this myself as well.

@Francois-Esquire
Copy link
Author

@brodybits Thank you! It looks like optional chaining was the culprit behind the failure (here), and it does seem to be supported in v5.2.0 of Terser. Upgrading would probably be the best option here - if you don't oppose, I'll raise a PR with the version upgrade accompanied by tests.

@brodybits
Copy link
Owner

Thanks for PR #20, reviewing it now.

I discovered there could also be issues if the source has only comments or blank lines, see #21.

I think this will need me to drop Node.js pre-14 support, see #18, will try to do this soon.

I am thinking that the issue with error handling could continue intermittently with the lag time between new ES features coming and terser updates, may have to keep #19 open for a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants