yarn init — Yarn CLI reference

Initialize a package in the current directory

Docs/Reference/CLI/init

yarn init

Initialize a package in the current directory

yarn init <TEMPLATE> <ARGS…>

This command creates a manifest and supporting project files in the current directory.

If the -p,--private or -w,--workspace options are set, the package will be private by default.

If the -w,--workspace option is set, the package will be configured to accept a set of workspaces in the packages/ directory.

At the root of a project, a .node-version file is created with the major of the latest Node.js release (unless there’s one already), which makes Yarn install that Node.js and run every script of the project with it. The --node-version option writes another version or range instead (latest being the default), and --no-node-version doesn’t create the file.

When a template is provided, Yarn initializes the project, installs the template in a temporary context, and runs its binary from the new project.

#--private, -pboolean

Mark the new package as private

#--workspace, -wboolean

Configure the package as a workspace root

#--name, -nboolean

Package name to write to the manifest

#--node-versionboolean

Node.js version or range to write to .node-version (the latest major by default; --no-node-version to create no file)

#-2boolean

Hidden legacy Yarn 1 compatibility flag

#--yes, -yboolean

Hidden legacy Yarn 1 compatibility flag

Examples#

Create a new package in the local directory

yarn init

Create a new private package in the local directory

yarn init -p

Create a new package that accepts workspaces in the packages/ directory

yarn init -w

Create a new package with a specific name

yarn init -n my-package

Create a new package using Node.js 24 rather than the latest release

yarn init --node-version=24