Bad JavaScript. Expected '(' in our webpack eval chunk
This is a quick blog post for resolving an issue this morning from webpack uglified/minified JavaScript. The error happens in IE and Edge, it simply says:
Expected ‘(‘
This was happening in the middle of a webpack minified chunk so the entire block was wrapped inside eval(““)
Steps
Navigate to the end of the webpack chunk, which will tell us the source of this chunk. Scroll past the sourcemap section to the end of the chunk (not the end of the file).
Find the original file that the chunk was created from - now run ESLint over it.
I didn’t have this handy in the build chain, so I ran it online https://eslint.org/demo/The error was spotted as there was a catch{} statement - in plain JavaScript - catch has to collect an argument. So the first syntax is incorrect. It must be the second syntax.
Modern browsers are more lenient so this error did not appear on all browsers.