vercel / turborepo

Build system optimized for JavaScript and TypeScript, written in Rust
https://turbo.build/repo/docs
MIT License
26.21k stars 1.81k forks source link

Check Yarn version before install #2250

Closed paulm17 closed 2 years ago

paulm17 commented 2 years ago

Describe the feature you'd like to request

Right now, when doing an installation it defaults to yarn 1.

It would be nice, if the dev is using the latest yarn, then npx create-turbo@latest should use it. Otherwise:

1) Install turborepo. Yarn 1 used. 2) Upgrade yarn:

yarn set version stable
➤ YN0000: Retrieving https://repo.yarnpkg.com/3.2.4/packages/yarnpkg-cli/bin/yarn.js
➤ YN0000: Saving the new release in .yarn/releases/yarn-3.2.4.cjs
➤ YN0000: Done in 0s 334ms

3) Run Yarn again:

➤ YN0070: Migrating from Yarn 1; automatically enabling the compatibility node-modules linker 👍

As then workspaces can be run:

yarn workspace web run dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000

Or else:

Internal Error: turbotest@workspace:.: This package doesn't seem to be present in your lockfile; run "yarn install" to update the lockfile

Describe the solution you'd like

npx create-turbo@latest uses the currently used version.

Describe alternatives you've considered

See above.

mehulkar commented 2 years ago

Right now, when doing an installation it defaults to yarn 1.

As far as I know, npx create-turbo@latest will prompt you to select the package manager you want to use. What turbo command are you using that is using Yarn 1 by default?

paulm17 commented 2 years ago

I had a lot of issues getting here and I must have forgotten a step / mis-remembering my history.

Going back and trying again. I am getting with yarn v3 initially:

paul@Pauls-MacBook-Pro tempo2 % yarn -v
1.22.19
paul@Pauls-MacBook-Pro tempo2 % yarn set version stable
➤ YN0000: Retrieving https://repo.yarnpkg.com/3.2.4/packages/yarnpkg-cli/bin/yarn.js
➤ YN0000: Saving the new release in .yarn/releases/yarn-3.2.4.cjs
➤ YN0000: Done in 0s 279ms
paul@Pauls-MacBook-Pro tempo2 % npx create-turbo@latest

>>> TURBOREPO

>>> Welcome to Turborepo! Let's get you set up with a new codebase.

? Where would you like to create your turborepo? myturborepo
? Which package manager do you want to use? yarn

>>> Created a new turborepo with the following:

 - apps/web: Next.js with TypeScript
 - apps/docs: Next.js with TypeScript
 - packages/ui: Shared React component library
 - packages/eslint-config-custom: Shared configuration (ESLint)
 - packages/tsconfig: Shared TypeScript `tsconfig.json`

>>  Installing dependencies...
Aborting installation.
  yarn install --no-immutable has failed.

It doesn't install even if I go into the newly created turborepo dir and execute the same yarn command.

Now I remember:

When I upgrade the yarn to version 3, it creates a package.json. If I set the install dir to ./ then it installs fine.

paul@Pauls-MacBook-Pro tempo2 % cd myturborepo
paul@Pauls-MacBook-Pro myturborepo % yarn set version stable
➤ YN0000: Retrieving https://repo.yarnpkg.com/3.2.4/packages/yarnpkg-cli/bin/yarn.js
➤ YN0000: Saving the new release in .yarn/releases/yarn-3.2.4.cjs
➤ YN0000: Done in 0s 310ms
paul@Pauls-MacBook-Pro myturborepo % ls
package.json
paul@Pauls-MacBook-Pro myturborepo % npx create-turbo@latest

>>> TURBOREPO

>>> Welcome to Turborepo! Let's get you set up with a new codebase.

? Where would you like to create your turborepo? ./
? Which package manager do you want to use? yarn

>>> Created a new turborepo with the following:

 - apps/web: Next.js with TypeScript
 - apps/docs: Next.js with TypeScript
 - packages/ui: Shared React component library
 - packages/eslint-config-custom: Shared configuration (ESLint)
 - packages/tsconfig: Shared TypeScript `tsconfig.json`

>>> Success! Your new Turborepo is ready.
Inside this directory, you can run several commands:

  yarn run build
     Build all apps and packages

  yarn run dev
     Develop all apps and packages

Turborepo will cache locally by default. For an additional
speed boost, enable Remote Caching with Vercel by
entering the following command:

  yarn dlx turbo login

We suggest that you begin by typing:

  yarn dlx turbo login

Sorry to move the goal posts slightly.

Here's what I'm using:

System:
    OS: macOS 12.4
    CPU: (10) arm64 Apple M1 Pro
    Memory: 804.28 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.4.0 
    Yarn: 3.2.4 
    npm: 8.12.1 
paulm17 commented 2 years ago

Found it:

.yarnrc.yml has the following

yarnPath: .yarn/releases/yarn-3.2.4.cjs

After an install, only the following

nodeLinker: "node-modules"

Of which yarn goes back to v1.

I don't know how to set yarn globally to v3, so that's the source of my issue.

I'm solving this by fixing this issue myself currently.

paulm17 commented 2 years ago

Thanks for your attention on this. But I have abandoned Yarn v3.

The final nail was that for whatever reason, the node_modules directory in UI could not be re-created when using certain packages. It was fine with the initial package.json, but when I use my existing yarn v1 package.json, yarn complains about missing dependencies, finishes but no directory.

After many issues, I've had enough.

mehulkar commented 2 years ago

I noticed a couple things:

I'm not sure if this is something turbo needs to watch out for, since I'm not sure what other ways the yarn version can be set globally 🤔.

Thanks for your attention on this. But I have abandoned Yarn v3.

Sorry to hear! I'm no expert in yarn, but if you figure out how create-turbo can set you up with Yarn better, I'd love to hear about it.

nathanhammond commented 2 years ago

If you run yarn --version in your current directory and it returns, say, 3.2.3 we will initialize a yarn@3 turborepo with the correct configuration. One way you can do that is to use corepack:

~$ corepack enable
~$ corepack prepare yarn@3.x --activate
Preparing yarn@3.x for immediate activation...
~$ yarn --version
3.2.3
~$ yarn create turbo --use-yarn issue-2250
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 3s 982ms
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: Done in 4s 136ms

>>> TURBOREPO

>>> Welcome to Turborepo! Let's get you set up with a new codebase.

>>> Created a new turborepo with the following:

 - apps/web: Next.js with TypeScript
 - apps/docs: Next.js with TypeScript
 - packages/ui: Shared React component library
 - packages/eslint-config-custom: Shared configuration (ESLint)
 - packages/tsconfig: Shared TypeScript `tsconfig.json`

>>> Success! Created a new Turborepo at "issue-2250".
Inside that directory, you can run several commands:

  yarn run build
     Build all apps and packages

  yarn run dev
     Develop all apps and packages

Turborepo will cache locally by default. For an additional
speed boost, enable Remote Caching with Vercel by
entering the following command:

  yarn dlx turbo login

We suggest that you begin by typing:

  cd issue-2250
  yarn dlx turbo login