-
-
Notifications
You must be signed in to change notification settings - Fork 233
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
Error: Premature close #1146
Comments
Hello, this error stack is generated by the above code |
Hi @FishOrBear, Thanks for reporting this. Do you get the same error when switching |
Thanks for your reply, same error. |
async function run()
{
const { execa } = await import('execa');
await execa("npm run tsc").pipeStdout("out.txt");
console.log(123);
} I used [email protected] and got no error. |
|
async function run()
{
const { execa } = await import('execa');
await execa("npm", ["run", "tsc"], {
stdout: {
file: "out.txt",
}
});
}
run(); I tried that and the same editor error stack appears. |
Thanks. Ok, what do you get with the following? Using Execa 9.3.1 (is this the version you're using?). import { execa } from 'execa';
await execa({stdout: {file: "out.txt"}})`npm run tsc`; I removed the dynamic import, but I am not sure whether there was a reason for it in the first place. Is your codebase in CommonJS, which would explain the dynamic import? |
{
"name": "run cur ts",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": [
"--nolazy",
"-r",
"ts-node/register/transpile-only",
],
"cwd": "${workspaceFolder}",
"internalConsoleOptions": "openOnSessionStart"
},
I currently use ts-node and cjs to run typescript code. |
Do you only get this error in VSCode, or can you reproduce in a terminal console (that is not inside VSCode)? There are several layers here: VSCode, ts-node, tsc, npm scripts. I cannot reproduce your bug locally, and I am suspecting this might be due to one of those "layers". |
I get no errors in the console. |
I think this question is similar to this one |
From reading this thread, it appears to be a problem with Node.js streams + VSCode debugger. Execa is just showing the problem here because the Just like the people on that other thread, I cannot reproduce locally in VSCode, so there might be something additional about your VSCode setup (and the other users who were having the same problem in that thread). To unblock you though, there might some workarounds. If the problem is indeed stream-related, you might want to try whether using something different that the async function run()
{
const {execa} = await import('execa');
const {writeFile} = await import('fs/promises');
const {stdout} = await execa`npm run tsc`;
await writeFile('./out.txt', stdout);
}
run(); (or if you're using ES modules and can use top-level await): import {execa} from 'execa';
import {writeFile} from 'fs/promises';
const {stdout} = await execa`npm run tsc`;
await writeFile('./out.txt', stdout); |
ok I create a repo 11-24-00.mp4 |
Both ways of writing give the same error.. Strange. |
I will use 8.0.1 first, this version is fine |
Thanks. Unfortunately, I cannot reproduce the problem with that repository.
Do you get the error without the import {execa} from 'execa';
await execa`npm run tsc`; |
hashicorp/setup-terraform#125 I found this, is it related? |
Yes.
This is not related. Is there a way to trigger this problem outside of VSCode? If not, this is a problem with VSCode unfortunately, and there is not much we'll be able to do here. :/ |
After updating from nodejs20.6 to nodejs22, the problem was solved |
Node 22 did include a few bug fixes related to streams, so this must have been the problem. Thanks for sharing the solution! |
The text was updated successfully, but these errors were encountered: