The Problem:
When attempting to create a Next.js application using the command "bun x create-next-app" within WSL Ubuntu, the process appears to freeze at the second prompt, "Would you like to use TypeScript? > No / Yes". Pressing any key or input does not result in any response, effectively hindering the creation of the Next.js application. What could be the underlying cause of this issue, and how can it be resolved?
The Solutions:
Solution 1: Opt-out of interactivity
The interactive mode of Bun CLI seems to be causing issues, particularly when running the create-next-app
command. To resolve this, you can bypass the interactive prompts and provide all the necessary information directly through command-line arguments.
For instance, instead of relying on the interactive prompts, you can enter the following command:
create-next-app <your-project-name> --ts --tailwind --eslint --app --src-dir --use-bun --import-alias "@/*"
Here’s what each option does:
<your-project-name>
: Replace this with the name you want to give your Next.js application.--ts
: Use TypeScript instead of JavaScript.--tailwind
: Integrate Tailwind CSS.--eslint
: Enable ESLint.--app
: Create apages/app
directory and a_app.js
file.--src-dir
: Customize the source directory name.--use-bun
: Use Bun as the JavaScript runtime.--import-alias
: Set up an import alias for your project.
For more information on these options, refer to the Next.js documentation on creating a new application: https://nextjs.org/docs/pages/api-reference/create-next-app#non-interactive
Update: The issue with the interactive mode of bun
was fixed in version 1.0.2
. To resolve the problem, you can update Bun by running bun upgrade
.
Q&A
Why does it get stuck at the second question when I run the command "bun x create-next-app" in WSL Ubuntu?
There is an open issue with interactivity in the "bun" project. It’s recommended to opt-out from interactivity and provide CLI parameters.
Is there another way to avoid the issue?
Yes, you can opt-out from interactivity and provide everything the CLI needs. Example: create-next-app
How to fix the issue?
Updating "bun" to version 1.0.2 via "bun upgrade" should resolve the problem.