Minified Bundle (terser) Produces Error: 500 Internal Server Error
See original GitHub issueWhat is your Scenario?
I have some code that fails when minified with terser, but works when not.
I binary-searched the compress flags to find that the combination of the compress
options reduce_vars
and unused
lead to code that causes the hammerhead web server to produce an error 500:
GET http://XXX.XXX.XXX.XXX:50331/XXX!s!utf-8/http://localhost:3000/script.js net::ERR_ABORTED 500 (Internal Server Error)
Then I binary-searched the bundle to create a snippet that causes the error:
const singleton = new class {
someMap=new Map;
dosomething() {
foo.map(({x, y}) => "doesnt matter")
}
};
Unfortunately I was not able to reduce it any further. Although I would not write that by hand, its valid JavaScript.
What is the Current behavior?
hammerhead sends Error: 500 Internal Server Error
What is the Expected behavior?
No Error
What is your public website URL? (or attach your complete example)
I created a repository: https://github.com/htho/testcafe-repro-error-500-terser
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
</body>
<script src="script.js"></script>
</html>
// script.js
// this is the part that makes hammerhead produce error 500.
// I was not able to reduce the example any further.
const singleton = new class {
someMap=new Map;
dosomething() {
foo.map(({x, y}) => "doesnt matter")
}
};
// this should make the test pass
document.body.insertAdjacentHTML("afterbegin", `<h1>It works!</h1>`)
What is your TestCafe test code?
import { fixture, Selector } from "testcafe";
fixture("internalServerError500")
.page("http://localhost:3000/")
test("script was executed", async (t) => {
await t.debug(); // take a look at the browser console
await t.expect(Selector("h1").exists).ok();
});
Your complete configuration file
none
Your complete test report
PS C:\XXX\github.com\htho\testcafe-repro-error-500-terser> npm run test
> repro-testcafe-error-500-terser@1.0.0 test
> testcafe chrome test.tc.ts
Running tests in:
- Chrome 106.0.0.0 / Windows 10
internalServerError500
× script was executed
1) AssertionError: expected false to be truthy
Browser: Chrome 106.0.0.0 / Windows 10
3 |fixture("internalServerError500")
4 | .page("http://localhost:3000/")
5 |
6 |test("script was executed", async (t) => {
7 | // await t.debug(); // take a look at the browser console
> 8 | await t.expect(Selector("h1").exists).ok();
9 |});
at <anonymous> (C:\XXX\github.com\htho\testcafe-repro-error-500-terser\test.tc.ts:8:43)
at <anonymous> (C:\XXX\github.com\htho\testcafe-repro-error-500-terser\test.tc.ts:8:71)
at __awaiter (C:\XXX\github.com\htho\testcafe-repro-error-500-terser\test.tc.ts:4:12)
at <anonymous> (C:\XXX\github.com\htho\testcafe-repro-error-500-terser\test.tc.ts:6:41)
1/1 failed (5s)
Screenshots
No response
Steps to Reproduce
- git clone https://github.com/htho/testcafe-repro-error-500-terser.git
- cd testcafe-repro-error-500-terser
- npm i
- npm run serve
- npm run test (in another terminal)
TestCafe version
2.0.1
Node.js version
v16.17.1
Command-line arguments
testcafe chrome test.tc.ts
Browser name(s) and version(s)
chrome 106
Platform(s) and version(s)
Windows 10
Other
No response
Issue Analytics
- State:
- Created a year ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
testcafe-hammerhead
not only injects code to the target page but modifies javascript code as well. That’s whyterser
throws an error. Thetestcafe-hammerhead
module just cannot process the uncommon code as you mentioned.The cause of both issues is similar. They occur due to the incorrect processing of class construction. So, we will take these cases into account when we start fixing it.