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

Script startup freezes: concurrently + mysql2 + tsx watch #525

Open
CodeSmith32 opened this issue Jan 9, 2025 · 0 comments
Open

Script startup freezes: concurrently + mysql2 + tsx watch #525

CodeSmith32 opened this issue Jan 9, 2025 · 0 comments

Comments

@CodeSmith32
Copy link

Brief

Following setup freezes:

concurrently "vite" "tsx watch index.ts"

index.ts

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

hello world does not log before app freezes.

Works:

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

Or:

index.ts

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:
{
  "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:
console.log("hello world");
import "mysql2";

With these files, run:

npm i

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

npm run dev

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

npm run dev-nowatch
npm run dev-index

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

console.log("hello world");
// import "mysql2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant