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

create-next-app prompts don't work on Windows #21111

Closed
dsherret opened this issue Nov 7, 2023 · 7 comments · Fixed by #23969
Closed

create-next-app prompts don't work on Windows #21111

dsherret opened this issue Nov 7, 2023 · 7 comments · Fixed by #23969
Assignees
Labels
bug Something isn't working correctly node API polyfill Related to various "node:*" modules APIs node compat

Comments

@dsherret
Copy link
Member

dsherret commented Nov 7, 2023

It's not possibe to change the selection from yes to no:

$ deno run -A npm:create-next-app@latest next-app
√ Would you like to use TypeScript? ... No / Yes
? Would you like to use ESLint? » No / Yes^[[D
√ Would you like to use ESLint? ... No / Yes
? Would you like to use Tailwind CSS? » No / Yes^[[D^[[B^[[A^[[C
√ Would you like to use Tailwind CSS? ... No / Yes
? Would you like to use `src/` directory? » No / Yes^[[C
√ Would you like to use `src/` directory? ... No / Yes
? Would you like to use App Router? (recommended) » No / Yes
√ Would you like to use App Router? (recommended) ... No / Yes
? Would you like to customize the default import alias (@/*)? » No / Yes
√ Would you like to customize the default import alias (@/*)? ... No / Yes
Creating a new Next.js app in V:\next-app.
@dsherret dsherret added bug Something isn't working correctly node compat labels Nov 7, 2023
@littledivy
Copy link
Member

@dsherret I can't reproduce on Windows, does it still happen?

@dsherret
Copy link
Member Author

dsherret commented Dec 4, 2023

@littledivy yes. It happens after accepting the first prompt:

image

@dsherret
Copy link
Member Author

dsherret commented Dec 4, 2023

Maybe try in vscode terminal with powershell.

@bartlomieju bartlomieju added the node API polyfill Related to various "node:*" modules APIs label Mar 4, 2024
@littledivy
Copy link
Member

littledivy commented Mar 29, 2024

Can reproduce. The selection is actually happening but not displayed until you hit Enter.

Recording.2024-03-29.094257.mp4

@littledivy
Copy link
Member

Simpler repro:

import EventEmitter from "node:events";
import readline from "node:readline";
import process from "node:process";

function prompt() {
  const rl = readline.createInterface({
    input: process.stdin,
  });
  readline.emitKeypressEvents(process.stdin, rl);

  process.stdin.setRawMode(true);

  const { promise, resolve } = Promise.withResolvers();
  const keypress = (str, key) => {
    process.stdin.setRawMode(false);
    rl.close();
    process.stdin.removeListener('keypress', keypress)
    console.log({ str, key })
    resolve()
  };

  process.stdin.on('keypress', keypress);
  return promise;
}

await prompt();
await prompt();

@littledivy
Copy link
Member

littledivy commented Mar 29, 2024

Repro using only process.stdin.

import process from "node:process";

function prompt() {
  process.stdin.setRawMode(true);

  const { promise, resolve } = Promise.withResolvers();

  const onData = (buf) => {
    process.stdin.setRawMode(false);
    process.stdin.removeListener('data', onData);
    console.log(buf);
    resolve();
  };

  process.stdin.on("data", onData);
  return promise;
}

await prompt();
await prompt();

@littledivy
Copy link
Member

Ok, I think this is the same issue as described in this old libuv PR: libuv/libuv#866

We need to unblock the stdin read thread when the stream is cancelled.

libuv sends a Enter key to the input buffer to unblock the read and restores it back, we can do something similar. We could also try using cancel handle.

littledivy added a commit that referenced this issue May 29, 2024
This patch fixes stdin read hanging on user input when switching tty
mode on Windows

Fixes #21111

On Windows, when switching from line to raw mode:
- Cancel ongoing console read by writing a return keypress to its input
buffer. This blocks the main thread until any ongoing read has been
cancelled to prevent interference with the screen state.
- On the read thread, restore the cursor position to where it was before
writing the enter, undoing its effect on the screen state.
- Restart reading and notify the main thread.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node API polyfill Related to various "node:*" modules APIs node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants