日本語

Creating a Project from a Template with Bun’s bun create

​​Bun​Elysia,Git,npm,Vite

With bun create, Bun can create a new project in one command from a Vite React starter, a template prepared for Bun, or a template folder you made yourself. It suits people who copy the same config files by hand every time, or who want to reuse a project starter their team agreed on.

In my test environment, I tried three templates: npm's create-vite, the elysia template that Bun provides, and my own template. I checked the files created, how git and installation are handled, and what happens when the target folder already contains files.

Note

The test environment was Ubuntu 24.04 (x86_64), Bun 1.4.4, and git 2.43.0. I fetched packages from registry.npmjs.org on November 24, 2026. I set HOME to an empty folder and started with no git user.name or user.email. In the output, I replaced the working folder path with /path/to. I did not test using a GitHub repository as a template (the GitHub API was not reachable from my test environment), passing a React component file, --open, Windows, or macOS.

Where bun create gets the template from

The syntax is bun create <template> [<destination>]. According to the official bun create documentation, the place the template is fetched from depends on what the name you pass matches. If you have your own template with the same name as npm's create-<name>, your own template is used.

  • If there is a folder for your own template (such as ~/.bun-create/<name>), Bun copies it.
  • If it is a template Bun provides (such as elysia), Bun fetches npm's @bun-examples/<name> and copies it.
  • If the name has the form <user>/<repo>, Bun fetches a GitHub repository.
  • Any other name is handed to npm's create-<name> (the same as bunx create-<name>).

When Bun does the copying itself, it then rewrites package.json, initializes git, and installs dependencies (same docs, "How bun create works"). When it hands off to npm's create-<name>, what happens after that depends on that tool.

Diagram showing that bun create either copies the template itself or hands it to npm's create-<name>, depending on the template type. When Bun copies, the steps run in this order: copy, rewrite package.json, git, install, and show the guidance.
Flow of bun create (drawn from the official Bun 1.4.4 docs and my test results)

Create a React project with npm's create-vite

bun create vite runs npm's create-vite. As the create-vite README explains, you can pass the project name and the scaffold to use with --template directly as arguments. I tested with the React and TypeScript scaffold react-ts.

txt
$ bun create vite my-vite --template react-ts
Resolving dependencies
Resolved, downloaded and extracted [4]
Saved lockfile

create-vite v9.3.4

|
o  Scaffolding project in /path/to/work/my-vite...
|
—  Done. Now run:

  cd my-vite
  bun install
  bun dev

The final guidance was bun install and bun dev. The created folder had neither .git nor node_modules. Bun initializes git and installs dependencies only when it copies the template itself. In this case, where create-vite handled the work, neither happened.

txt
$ ls -A my-vite
.gitignore
.oxlintrc.json
README.md
index.html
package.json
public
src
tsconfig.app.json
tsconfig.json
tsconfig.node.json
vite.config.ts

I followed the guidance, ran bun install, and then bun run build. The build succeeded (the output of bun install is omitted).

txt
$ bun run build
$ tsc -b && vite build
vite v8.3.8 building client environment for production...
transforming...
✓ 20 modules transformed.
rendering chunks...
computing gzip size...
dist/index.html                   0.45 kB │ gzip:  0.29 kB
dist/assets/react-CHdo91hT.svg    4.12 kB │ gzip:  2.06 kB
dist/assets/vite-BF8QNONU.svg     8.70 kB │ gzip:  1.60 kB
dist/assets/hero-CLDdwZDr.png    13.05 kB
dist/assets/index-D64VDMd1.css    4.10 kB │ gzip:  1.47 kB
dist/assets/index-GpEN3EET.js   222.44 kB │ gzip: 69.28 kB

✓ built in 154ms

bun create react and bun create next don't work

bun create react and bun create next ended after showing guidance, without creating a project (exit code 1). The official docs also say these two names only point to other tools.

txt
$ bun create react
The "react" template has been deprecated.
It is recommended to use "react-app" or "vite" instead.

To create a project using Create React App, run

  bun create react-app

To create a React project using Vite, run

  bun create vite

Then select "React" from the list of frameworks.
$ bun create next
warn: No template create-next found.
To create a project with the official Next.js scaffolding tool, run
  bun create next-app [destination]

Use Bun's elysia template

elysia is one of the templates Bun publishes to npm. The official docs' explanation of how bun create works lists three: elysia, elysia-buchta, and stric. In this case, Bun extracts the files and then also handles git and installation. I ran it with git's user.name and user.email not set.

txt
$ bun create elysia my-elysia
Fetching package.json... 
Parsing package.json [912] 
Downloading tarball [912] 
Downloading tarball [4244] 
Decompressing elysia... 
Extracting elysia... 
Updating package.json... 
note: git has no user.name and user.email, files staged but not committed

[12.00ms] git

$ bun install
bun install v1.4.4 (38afee6c8)
Resolving dependencies
Resolved, downloaded and extracted [78]
Saved lockfile

+ bun-types@1.4.5
+ elysia@1.4.32

20 packages installed [410.00ms]

[414.00ms] bun install


[632.00ms] bun create elysia

Come hang out in bun's Discord: https://bun.com/discord

-----

A local git repository was created for you and dependencies were installed automatically.

Created elysia project successfully

# To get started, run:

  cd my-elysia
  bun run src/index.ts

The whole process took 632 ms. The name in package.json had been rewritten to the destination folder name, my-elysia. The version stayed at 1.0.50 from the template, and the elysia dependency is pinned to latest.

json
{
  "name": "my-elysia",
  "version": "1.0.50",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "bun run --watch src/index.ts"
  },
  "dependencies": {
    "elysia": "latest"
  },
  "devDependencies": {
    "bun-types": "latest"
  },
  "module": "src/index.js"
}

As the note in the output says, without user.name and user.email, the process stopped after git init and staging the files. No commit was made.

txt
$ git log --oneline; git status --short
fatal: your current branch 'master' does not have any commits yet
A  .gitignore
A  README.md
A  package.json
A  src/index.ts
A  tsconfig.json
?? bun.lock

When I created the project after setting user.name and user.email, one commit, "Initial commit (via bun create)", was made. In both cases, bun.lock was not in the commit. As the official docs say, the git processing finishes before bun install runs.

txt
$ git log --oneline && git status --short
eed944e Initial commit (via bun create)
?? bun.lock

I started the server with bun run src/index.ts, as the guidance said.

txt
$ bun run src/index.ts
🦊 Elysia is running at localhost:3000

While the server was running, I ran curl from another terminal, and the template's response came back.

txt
$ curl -s http://localhost:3000/
Hello Elysia

Skip git and install

With --no-git and --no-install, the command only placed the files. None of .git, node_modules, or bun.lock were created.

txt
$ bun create elysia my-elysia3 --no-git --no-install
(出力は省略)
$ ls -A my-elysia3
.gitignore
README.md
package.json
src
tsconfig.json

When the target folder already has files

I also checked what happens when the target is a folder that already exists. When I created the project in a folder containing README.md and tsconfig.json, Bun listed tsconfig.json, which conflicts with a file in the template, and stopped without changing anything (exit code 1).

txt
$ bun create elysia exists --no-install --no-git
(途中の出力は省略)
error: The directory exists/ contains files that could conflict:

  tsconfig.json

To overwrite them, use --force

However, only tsconfig.json was listed; README.md was not on the list. After I deleted tsconfig.json and ran the command again, it finished without an error, and the README.md I had written was replaced with the template's content.

txt
$ cat exists/README.md
私のメモ
$ rm exists/tsconfig.json
$ bun create elysia exists --no-install --no-git
(出力は省略)
$ head -1 exists/README.md
# Elysia with Bun runtime
Warning

In my Bun 1.4.4 test environment, an existing README.md in the target folder was overwritten without any check. The official docs say that files are not overwritten by default, but the actual behavior was different. If a folder contains files you want to keep, don't create the project directly in it. Create it in an empty folder and then move the files over.

Files that stopped the command were replaced with the template's versions when I added --force. The tsconfig.json I had set to {} now has the template's content.

txt
$ bun create elysia exists --no-install --no-git --force
(出力は省略)
$ head -3 exists/tsconfig.json
{
  "compilerOptions": {
    /* Visit https://aka.ms/tsconfig to read more about this file */

Use a GitHub repository as a template

According to the official docs, bun create <user>/<repo> [<destination>] uses the contents of a GitHub repository as the template. If you omit the destination, the folder is named after the repository. The git initialization and bun install that follow are the same as for other templates. To use a private repository, or to avoid API rate limits, set the environment variable GITHUB_TOKEN (the environment variable table in the same docs).

Create your own template

You can keep a scaffold you use often as a folder in ~/.bun-create/<name>, and then use it with bun create <name> (the official docs on local templates). I made the following folder named my-api. The node_modules folder is there to confirm that it is not copied.

txt
~/.bun-create/my-api
~/.bun-create/my-api/gitignore
~/.bun-create/my-api/node_modules
~/.bun-create/my-api/node_modules/dummy
~/.bun-create/my-api/node_modules/dummy/index.js
~/.bun-create/my-api/package.json
~/.bun-create/my-api/src
~/.bun-create/my-api/src/index.ts

In package.json, under the "bun-create" key, you can write commands to run before and after installation (preinstall and postinstall), and a command to show at the end (start) (the Setup logic section of the official docs). postinstall can take several commands as an array. If you write the name of a script from package.json's scripts, that script runs.

json
{
  "name": "my-api-template",
  "version": "0.1.0",
  "scripts": {
    "dev": "bun run --watch src/index.ts",
    "hello": "echo hello from scripts.hello"
  },
  "dependencies": {
    "is-number": "7.0.0"
  },
  "bun-create": {
    "preinstall": "echo 'preinstall: 依存を入れる前'",
    "postinstall": ["echo 'postinstall: 1つめ'", "hello"],
    "start": "bun run dev"
  }
}

I ran bun create my-api api1, and the steps ran in this order: git, preinstall, bun install, postinstall. The hello in postinstall ran as bun run hello, and the final guidance showed bun run dev, which is what I wrote in start.

txt
$ bun create my-api api1
Copying files... 

[11.00ms] git
$ echo 'preinstall: 依存を入れる前'
preinstall: 依存を入れる前

$ bun install
bun install v1.4.4 (38afee6c8)
Resolving dependencies
Resolved, downloaded and extracted [4]
Saved lockfile

+ is-number@7.0.0

1 package installed [74.00ms]

[77.00ms] bun install

$ echo 'postinstall: 1つめ'
postinstall: 1つめ
$ bun run hello
$ echo hello from scripts.hello
hello from scripts.hello

[101.00ms] bun create /path/to/home/.bun-create/my-api

Come hang out in bun's Discord: https://bun.com/discord

-----

A local git repository was created for you and dependencies were installed automatically.

Created my-api project successfully

# To get started, run:

  cd api1
  bun run dev

In the generated project's package.json, name had become api1, and the "bun-create" key had been removed.

json
{
  "name": "api1",
  "version": "0.1.0",
  "scripts": {
    "dev": "bun run --watch src/index.ts",
    "hello": "echo hello from scripts.hello"
  },
  "dependencies": {
    "is-number": "7.0.0"
  }
}

I also confirmed the following:

  • The template's gitignore was renamed to .gitignore. Its content is one line, node_modules.
  • Inside node_modules, only is-number was present. The dummy package I placed in the template was not copied.
  • Because I had set user.name and user.email, the commit "Initial commit (via bun create)" was made.

The official docs say the gitignore rename is needed because npm removes .gitignore when it publishes a package.

With --no-install, neither the installation nor the preinstall and postinstall commands ran. The output had no echo lines, and there was no node_modules.

txt
$ bun create my-api api2 --no-install
Copying files... 

[11.00ms] git

[12.00ms] bun create /path/to/home/.bun-create/my-api

Come hang out in bun's Discord: https://bun.com/discord

A local git repository was created for you.

Created my-api project successfully

# To get started, run:

  cd api2
  bun run dev
$ ls -A api2
.git
.gitignore
package.json
src

Change where templates are stored

Besides ~/.bun-create, there are three other ways to place templates. All three worked in my test environment.

  • Set the environment variable BUN_CREATE_DIR to a folder that contains your templates.
  • Put the template in .bun-create/<name> inside the working folder. This is a template used only within that project.
  • Pass a template folder by absolute path, as in bun create /path/to/template mydir.

For example, the template tiny, placed in a folder set as BUN_CREATE_DIR, could be used like this (paths replaced):

txt
$ BUN_CREATE_DIR="/path/to/shared-templates" bun create tiny tiny1 --no-git
(出力は省略)
$ cat tiny1/package.json; ls tiny1
{
  "name": "tiny1"
}
hello.txt
package.json

​Posted by 86