Script startup freezes: `concurrently` + `mysql2` + `tsx watch`

Author: CodeSmith32Created Jan 9, 2025Updated Jun 3, 2025
Labelspull request welcome

Brief

Following setup freezes:

bash
concurrently "vite" "tsx watch index.ts"

index.ts

typescript
console.log("hello world");
import "mysql2"

hello world does not log before app freezes.

Works:

bash
# terminal 1:
vite
# terminal 2:
tsx watch index.ts

Or:

index.ts

typescript
console.log("hello world");
// import "mysql2"

Detailed Explanation

I was using concurrently with the mysql2 package, with tsx watch to run my code and watch for changes. At some point, it started freezing completely on startup. I even added a console.log at the very beginning of the entry point script that would not even print, which made me think it was an import issue (since I think imports run even before that console.log).

After disabling various parts of code, I finally disabled my import for mysql2 and it started running again. But, even if I did not use the value imported, just having the import "mysql2" by itself would cause it to freeze.

Finally, I tried running the two-part application without concurrently and just in separate terminals, and it worked fine, with the mysql2 import and everything.

I presume this is an issue with concurrently, mysql2, and tsx watch since it works fine if I remove any one of these three dependents (using tsx not in watch mode also works). I switched to npm-run-all and it works fine now. Not sure exactly what mysql2 is doing as a side-effect, or what breaks it when using concurrently.

Environment

OS: Windows 10 x64 Terminal: Powershell integrated in VSCode 1.96.2

Minimal Example

I've reproduced this issue with two files:

  1. The following minimal package.json:
javascript
{
  "name": "test",
  "version": "0.0.1",
  "scripts": {
    "dev": "concurrently \"vite\" \"tsx watch index.ts\"",
    "dev-nowatch": "concurrently \"vite\" \"tsx index.ts\"",
    "dev-index": "tsx watch index.ts"
  },
  "dependencies": {
    "mysql2": "^3.12.0"
  },
  "devDependencies": {
    "concurrently": "^9.1.2",
    "tsx": "^4.19.2",
    "typescript": "~5.6.2",
    "vite": "^6.0.5"
  }
}
  1. The following file, index.ts:
typescript
console.log("hello world");
import "mysql2";

With these files, run:

bash
npm i

The following shows that hello world does not log as expected:

bash
npm run dev

The following commands show that it does print when not using concurrently or when not using watch mode:

bash
npm run dev-nowatch
npm run dev-index

Also try commenting out import "mysql2" to see that this also works:

typescript
console.log("hello world");
// import "mysql2"

Source: open-cli-tools/concurrently