这是indexloc提供的服务,不要输入任何密码
Skip to content

Running a turbo upgrade fails when running it twice #8495

@maxshay

Description

@maxshay

Verify canary release

  • I verified that the issue exists in the latest Turborepo 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

Metadata

Metadata

Assignees

Labels

kind: bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions