question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Minified Bundle (terser) Produces Error: 500 Internal Server Error

See original GitHub issue

What 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

  1. git clone https://github.com/htho/testcafe-repro-error-500-terser.git
  2. cd testcafe-repro-error-500-terser
  3. npm i
  4. npm run serve
  5. 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:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
AlexKamaevcommented, Nov 4, 2022

testcafe-hammerhead not only injects code to the target page but modifies javascript code as well. That’s why terser throws an error. The testcafe-hammerhead module just cannot process the uncommon code as you mentioned.

0reactions
AlexKamaevcommented, Nov 7, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is a 500 Internal Server Error? - Allconnect.com
A 500 Internal Server Error is an umbrella term for several issues often involving the server of the website you're trying to reach....
Read more >
Resolving "Failed to minify the bundle" Errors - CircleCI Support
TerserWebpackPlugin. The following error message is usually related to running out of memory during a job: Failed to minify the bundle.
Read more >
Error 500 when activating JS minify from latest update
In the JS console the error is: “…. net::ERR_ABORTED 500 (Internal Server Error)” next to the minified file name. This is a screenshot...
Read more >
[Solved]-Failed to minify the bundle. Error - appsloveworld.com
Coding example for the question Failed to minify the bundle. Error: static/js/main.68c81611.chunk.js from Terser-Reactjs.
Read more >
4 Reasons Why Your Source Maps are Broken - Sentry Blog
We're going to presume that you've already produced a source map using ... a SourceMap HTTP header value when requesting your minified file....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found