berry icon indicating copy to clipboard operation
berry copied to clipboard

[Bug?]: Installation doc is misleading, not applicable for an existing project

Open ADTC opened this issue 1 year ago • 0 comments

Self-service

  • [ ] I'd be willing to implement a fix
  • [x] I'd be willing to rewrite the docs

Describe the bug

This page:

  • https://yarnpkg.com/getting-started/install

Tells me to run yarn init -2. But doing so in an existing project will wipe out the existing package.json file and initialize a new project in the same directory without any warning.

This is misleading for a developer who just freshly cloned the repo of an existing project and is trying to install yarn for the first time, and to install all the packages in the project.

To reproduce

Try to install yarn inside an existing project, which you have just cloned from a remore repo freshly.

Environment

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 22.7.0 - /private/var/folders/xy/d6t6p4zs65zg0sb924lv14t80000gn/T/xfs-05ba66b1/node
    Yarn: 4.4.0 - /private/var/folders/xy/d6t6p4zs65zg0sb924lv14t80000gn/T/xfs-05ba66b1/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v22.7.0/bin/npm

Additional context

The instructions must make it clear that the init command is for new projects, and it should give alternative instructions for existing projects, which is to run yarn instead. (Not the init command.)

Also, the init command should warn when it's possibly erroneously run inside a project that has an existing package.json file before overwriting the file - guiding the user to cancel the operation and run yarn instead.

ADTC avatar Aug 25 '24 18:08 ADTC