vercel / turborepo

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

Running a turbo upgrade fails when running it twice #8495

Open maxshay opened 5 months ago

maxshay commented 5 months ago

Verify canary release

Link to code that reproduces this issue

na

What package manager are you using / does the bug impact?

pnpm

What operating system are you using?

Mac

Which canary version will you have in your reproduction?

na

Describe the Bug

While upgrading turborepo with npx @turbo/codemod@latest update I ran into the following error:

Error message:

(3/11) Running migrate-env-var-dependencies
 INFO  Migrating environment variable dependencies from "globalDependencies" and "dependsOn" to "env" in "turbo.json"... 

Unexpected error. Please report it as a bug:
TypeError: Cannot convert undefined or null to object
    at Function.values (<anonymous>)
    at Pu (/Users/mshay/.npm/_npx/36146fcc85b26196/node_modules/@turbo/codemod/dist/transforms/migrate-env-var-dependencies.js:39:6831)
    at Object.WE [as transformer] (/Users/mshay/.npm/_npx/36146fcc85b26196/node_modules/@turbo/codemod/dist/transforms/migrate-env-var-dependencies.js:39:8345)
    at Command.Wh (/Users/mshay/.npm/_npx/36146fcc85b26196/node_modules/@turbo/codemod/dist/cli.js:46:9172)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Command.parseAsync (/Users/mshay/.npm/_npx/36146fcc85b26196/node_modules/commander/lib/command.js:935:5)

Expected Behavior

Does not error and completes the migration successfully after running a second time.

To Reproduce

Migrating turbo repo from 1.13.3 to latest with npx @turbo/codemod@latest update. I was also updating eslint versions and some internal packages' (eslint config and typescript config) names and didn't replace all references in my apps that referenced them. Not ideal but it happened this way. Running npx @turbo/codemod@latest update the first time resulted in what seemed like a successfull migration:

mshay@Maksims-MBP appName % npx @turbo/codemod@latest update
Need to install the following packages:
  @turbo/codemod@2.0.4
Ok to proceed? (y) y
? Where is the root of the repo to migrate? .
Upgrading turbo from 1.13.3 to 2.0.4 (11 required codemods) 

(1/11) Running add-package-manager
 INFO  Set "packageManager" key in root "package.json" file... 
 MODIFIED  package.json 

Results:
┌──────────────┬────────────┬───────────┬───────────┬────────┐
│   (index)    │   action   │ additions │ deletions │ error  │
├──────────────┼────────────┼───────────┼───────────┼────────┤
│ package.json │ 'modified' │     1     │     1     │ 'None' │
└──────────────┴────────────┴───────────┴───────────┴────────┘

(2/11) Running create-turbo-config
 INFO  Migrating "package.json" "turbo" key to "turbo.json" file... 
 UNCHANGED  turbo.json 
 UNCHANGED  package.json 

Results:
┌──────────────┬─────────────┬───────────┬───────────┬────────┐
│   (index)    │   action    │ additions │ deletions │ error  │
├──────────────┼─────────────┼───────────┼───────────┼────────┤
│  turbo.json  │ 'unchanged' │     0     │     0     │ 'None' │
│ package.json │ 'unchanged' │     0     │     0     │ 'None' │
└──────────────┴─────────────┴───────────┴───────────┴────────┘

(3/11) Running migrate-env-var-dependencies
 INFO  Migrating environment variable dependencies from "globalDependencies" and "dependsOn" to "env" in "turbo.json"... 
 UNCHANGED  turbo.json 

Results:
┌────────────┬─────────────┬───────────┬───────────┬────────┐
│  (index)   │   action    │ additions │ deletions │ error  │
├────────────┼─────────────┼───────────┼───────────┼────────┤
│ turbo.json │ 'unchanged' │     0     │     0     │ 'None' │
└────────────┴─────────────┴───────────┴───────────┴────────┘

(4/11) Running stabilize-env-mode
 INFO  Rewriting `experimentalPassThroughEnv` and `experimentalGlobalPassThroughEnv` 
 UNCHANGED  turbo.json 
 UNCHANGED  apps/appName/turbo.json 

Results:
┌────────────────────────────┬─────────────┬───────────┬───────────┬────────┐
│          (index)           │   action    │ additions │ deletions │ error  │
├────────────────────────────┼─────────────┼───────────┼───────────┼────────┤
│         turbo.json         │ 'unchanged' │     0     │     0     │ 'None' │
│ apps/appName/turbo.json │ 'unchanged' │     0     │     0     │ 'None' │
└────────────────────────────┴─────────────┴───────────┴───────────┴────────┘

(5/11) Running transform-env-literals-to-wildcards
 INFO  Rewriting env vars to support wildcards 
 UNCHANGED  turbo.json 
 UNCHANGED  apps/appName/turbo.json 

Results:
┌────────────────────────────┬─────────────┬───────────┬───────────┬────────┐
│          (index)           │   action    │ additions │ deletions │ error  │
├────────────────────────────┼─────────────┼───────────┼───────────┼────────┤
│         turbo.json         │ 'unchanged' │     0     │     0     │ 'None' │
│ apps/appName/turbo.json │ 'unchanged' │     0     │     0     │ 'None' │
└────────────────────────────┴─────────────┴───────────┴───────────┴────────┘

(6/11) Running clean-globs
 UNCHANGED  turbo.json 
 UNCHANGED  apps/appName/turbo.json 

Results:
┌────────────────────────────┬─────────────┬───────────┬───────────┬────────┐
│          (index)           │   action    │ additions │ deletions │ error  │
├────────────────────────────┼─────────────┼───────────┼───────────┼────────┤
│         turbo.json         │ 'unchanged' │     0     │     0     │ 'None' │
│ apps/appName/turbo.json │ 'unchanged' │     0     │     0     │ 'None' │
└────────────────────────────┴─────────────┴───────────┴───────────┴────────┘

(7/11) Running add-package-names
 INFO  Validating that each package has a unique "name"... 
 MODIFIED  package.json 
 MODIFIED  apps/appName/package.json 

Results:
┌──────────────────────────────┬────────────┬───────────┬───────────┬────────┐
│           (index)            │   action   │ additions │ deletions │ error  │
├──────────────────────────────┼────────────┼───────────┼───────────┼────────┤
│         package.json         │ 'modified' │     1     │     0     │ 'None' │
│ apps/appName/package.json │ 'modified' │     1     │     1     │ 'None' │
└──────────────────────────────┴────────────┴───────────┴───────────┴────────┘

(8/11) Running migrate-dot-env
 INFO  Moving entries in `dotEnv` key in task config to `inputs` 
 UNCHANGED  turbo.json 
 UNCHANGED  apps/appName/turbo.json 

Results:
┌────────────────────────────┬─────────────┬───────────┬───────────┬────────┐
│          (index)           │   action    │ additions │ deletions │ error  │
├────────────────────────────┼─────────────┼───────────┼───────────┼────────┤
│         turbo.json         │ 'unchanged' │     0     │     0     │ 'None' │
│ apps/appName/turbo.json │ 'unchanged' │     0     │     0     │ 'None' │
└────────────────────────────┴─────────────┴───────────┴───────────┴────────┘

(9/11) Running rename-output-mode
 INFO  Renaming `outputMode` key in task config to `outputLogs` 
 UNCHANGED  turbo.json 
 UNCHANGED  apps/appName/turbo.json 

Results:
┌────────────────────────────┬─────────────┬───────────┬───────────┬────────┐
│          (index)           │   action    │ additions │ deletions │ error  │
├────────────────────────────┼─────────────┼───────────┼───────────┼────────┤
│         turbo.json         │ 'unchanged' │     0     │     0     │ 'None' │
│ apps/appName/turbo.json │ 'unchanged' │     0     │     0     │ 'None' │
└────────────────────────────┴─────────────┴───────────┴───────────┴────────┘

(10/11) Running rename-pipeline
 INFO  Renaming `pipeline` key in turbo.json to `tasks` 
 MODIFIED  turbo.json 
 MODIFIED  apps/appName/turbo.json 

Results:
┌────────────────────────────┬────────────┬───────────┬───────────┬────────┐
│          (index)           │   action   │ additions │ deletions │ error  │
├────────────────────────────┼────────────┼───────────┼───────────┼────────┤
│         turbo.json         │ 'modified' │     1     │     1     │ 'None' │
│ apps/appName/turbo.json │ 'modified' │     1     │     1     │ 'None' │
└────────────────────────────┴────────────┴───────────┴───────────┴────────┘

(11/11) Running stabilize-ui
 INFO  Renaming `experimentalUI` key in turbo.json to `ui` 
 UNCHANGED  turbo.json 

Results:
┌────────────┬─────────────┬───────────┬───────────┬────────┐
│  (index)   │   action    │ additions │ deletions │ error  │
├────────────┼─────────────┼───────────┼───────────┼────────┤
│ turbo.json │ 'unchanged' │     0     │     0     │ 'None' │
└────────────┴─────────────┴───────────┴───────────┴────────┘

Upgrading turbo with pnpm add turbo@latest --save-dev -w 

Migration failed
Unable to upgrade turbo: Error: Command failed: pnpm add turbo@latest --save-dev -w

Until it got to the last part there of upgrading turbo with pnpm. And since package references were wrong pnpm failed, thus migration failed.

I fixed the references, ran pnpm install in the root to make sure, and reran npx @turbo/codemod@latest update and got the error noted in Describe the Bug

Since the migrations succeed the first time I manually updated the package.json turbo version to "^2.0.3" and pnpm installed. And everything seemed to work ok.

A rare edge case but still reporting nonetheless.

Additional context

cmanuelpriver commented 5 months ago

@maxshay Could you solve it? I have the same problem

maxshay commented 5 months ago

@cmanuelpriver not really solved, but the first time i ran it, it seems like the migrations part was all successful. So i manually updated the turbo version from "^1.13.3" to "^2.0.4" in the package json, and did a pnpm install. And it seems to run fine.

If that doesn't work for you just create a separate turborepo app using the lastest version using the cmd line. And make sure the turbo related files look the same. Shouldn't be a lot of files for a regular project.

cmanuelpriver commented 5 months ago

I solved, I had problems with nvm and windows, I deleted everything and tried again and it worked, I never knew what the specific problem was.

cmanuelpriver commented 5 months ago

@maxshay Thank you for your help

Nicolasvegam commented 5 months ago

same problem here..

JulianKingman commented 3 months ago

I was facing the same issue. It seems the migration is expecting a dotEnv property in tasks.build in turbo.json. I added that, and it completed successfully.


{
  "$schema": "https://turbo.build/schema.json",
  "globalDependencies": ["**/.env.*local"],
  "tasks": {
    "build": {
      "env": [],
      "dotEnv": [".env", ".env.local"] // <-- add this
    }
    // ...