turbo icon indicating copy to clipboard operation
turbo copied to clipboard

@turbo/codemod Unexpected error. Please report it as a bug

Open shuther opened this issue 1 year ago • 1 comments

Verify canary release

  • [X] 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?

npm, Yarn v2/v3/v4 (node_modules linker only)

What operating system are you using?

Mac

Which canary version will you have in your reproduction?

1.13.4

Describe the Bug

I tried to migrate from 1.13.4 -> 2.x using: npx @turbo/codemod update --force (I also tried @canary version)

Need to install the following packages:
@turbo/[email protected]
Ok to proceed? (y) y

npm warn deprecated [email protected]: cross-spawn no longer requires a build toolchain, use it instead
WARNING: Git directory is not clean. Forcibly continuing...
? Where is the root of the repo to migrate? .
Upgrading turbo from 1.13.4 to 2.0.14 (11 required codemods) 

(1/11) Running add-package-manager
 INFO  "packageManager" already set in root "package.json" 

(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"... 

Unexpected error. Please report it as a bug:
TypeError: Cannot convert undefined or null to object
    at Function.values (<anonymous>)
    at Iu (/Users/shuther/.npm/_npx/24554e532d5698bb/node_modules/@turbo/codemod/dist/transforms/migrate-env-var-dependencies.js:39:7068)
    at Object.zS [as transformer] (/Users/shuther/.npm/_npx/24554e532d5698bb/node_modules/@turbo/codemod/dist/transforms/migrate-env-var-dependencies.js:39:8582)
    at Command.Zh (/Users/shuther/.npm/_npx/24554e532d5698bb/node_modules/@turbo/codemod/dist/cli.js:46:9079)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Command.parseAsync (/Users/shuther/.npm/_npx/24554e532d5698bb/node_modules/commander/lib/command.js:935:5)

Expected Behavior

upgrade turbo to latest version

To Reproduce

n/a

Additional context

migrate failed with (but it seems every steps to change turbo.json went well, the latest one is 11/11 - Running stabilize-ui)

Migration failed
Unable to determine upgrade command
➜  web-main3-git git:(gitbutler/integration) ✗ npx @turbo/codemod      

turbo.json after the 1st pass of migrate before update again:

{
  "$schema": "https://turborepo.org/schema1.json",
  "globalDependencies": [
    "**/.env",
    "**/.env.*local",
    "tsconfig.json"
  ],
  "globalEnv": [
    "PACKAGE_VERSION",
    "NODE_ENV"
  ],
  "globalPassThroughEnv": [
    "CROWDIN_PERSONAL_TOKEN",
    "CROWDIN_PROJECT_ID",
    "GITHUB_TOKEN"
  ],
  "tasks": {
    "topo": {
      "dependsOn": [
        "^topo"
      ]
    },
    "build": {
      "dependsOn": [
        "^build"
      ],
      "env": [
        "\\*",
        "RESEND_API_KEY",
        "\\!NEXT_PUBLIC_GIT_\\*",
        "TINY_BIRD_API_KEY",
        "NODE_ENV",
        "VERCEL_URL"
      ],
      "outputs": [
        ".next/**",
        "!.next/cache/**",
        "next-env.d.ts"
      ],
      "inputs": [
        "$TURBO_DEFAULT$",
        "!README.md"
      ]
    },
    "dev": {
      "persistent": true,
      "cache": false
    },
    "format": {
      "outputs": [
        "node_modules/.cache/.prettiercache"
      ],
      "outputLogs": "new-only"
    },
    "lint": {
      "dependsOn": [
        "^topo"
      ],
      "outputs": [
        "node_modules/.cache/.eslintcache"
      ]
    },
    "typecheck": {
      "dependsOn": [
        "^topo"
      ],
      "outputs": [
        "node_modules/.cache/tsbuildinfo.json"
      ]
    },
    "clean": {
      "cache": false
    }
  }
}

shuther avatar Aug 24 '24 14:08 shuther

"tasks" is available to turbo 2.x. Therefore, the error is occurring because "tasks" cannot be read. As a solution, change "tasks" to "pipeline," which can be read by version 1, and then run npx @turbo/codemod update, which will automatically update it.

jongjunpark avatar Sep 26 '24 04:09 jongjunpark

I believe this is fixed by https://github.com/vercel/turborepo/pull/10295. Please let me know if not and I'll reopen.

anthonyshew avatar Apr 08 '25 22:04 anthonyshew