Cysharp/UniTask · error · Exception

package.json and env version are mismatched.

Error message

package.json and env version are mismatched.

What it means

Thrown by PackageExporter, a Unity Editor build tool that exports the UniTask package. It reads the UNITY_PACKAGE_VERSION environment variable and the version field from package.json; if both are present and differ, the export aborts. This prevents shipping a .unitypackage whose embedded version label disagrees with the CI-controlled version.

Source

Thrown at src/UniTask/Assets/Editor/PackageExporter.cs:57

        var versionJson = Path.Combine(Application.dataPath, root, "package.json");

        if (File.Exists(versionJson))
        {
            var v = JsonUtility.FromJson<Version>(File.ReadAllText(versionJson));

            if (!string.IsNullOrEmpty(version))
            {
                if (v.version != version)
                {
                    var msg = $"package.json and env version are mismatched. UNITY_PACKAGE_VERSION:{version}, package.json:{v.version}";

                    if (Application.isBatchMode)
                    {
                        Console.WriteLine(msg);
                        Application.Quit(1);
                    }

                    throw new Exception("package.json and env version are mismatched.");
                }
            }

            version = v.version;
        }

        return version;
    }

    public class Version
    {
        public string version;
    }
}

#endif

View on GitHub (pinned to ceac8d6946)

Solutions

  1. Set UNITY_PACKAGE_VERSION to the exact same string as the "version" field in package.json (or update package.json to match the env var).
  2. If driving versions from CI, ensure the same step that sets UNITY_PACKAGE_VERSION also patches package.json before invoking Unity.
  3. If package.json should be the single source of truth, unset UNITY_PACKAGE_VERSION from the environment so the check is skipped entirely.
  4. Verify there are no leading/trailing whitespace or 'v' prefix mismatches between the two values.

Example fix

// before: package.json has "version":"2.5.1" but CI sets:
//   UNITY_PACKAGE_VERSION=2.3.0
// after: align them
//   UNITY_PACKAGE_VERSION=2.5.1
Defensive patterns

Strategy: validation

Validate before calling

// Before running the export, verify versions match
var envVersion = Environment.GetEnvironmentVariable("UNITY_PACKAGE_VERSION");
if (!string.IsNullOrEmpty(envVersion))
{
    var pkg = JsonUtility.FromJson<Version>(File.ReadAllText("package.json"));
    if (pkg.version != envVersion)
        throw new InvalidOperationException($"Version mismatch: env={envVersion}, package.json={pkg.version}");
}
// Shell alternative for CI:
//   PKG=$(jq -r .version package.json)
//   if [ -n "$UNITY_PACKAGE_VERSION" ] && [ "$UNITY_PACKAGE_VERSION" != "$PKG" ]; then
//     echo "Set UNITY_PACKAGE_VERSION=$PKG"; exit 1
//   fi

Prevention

When it happens

Trigger: Running PackageExporter in batch mode (CI) with UNITY_PACKAGE_VERSION set in the environment to a value that differs from the "version" field in package.json. The code first writes the mismatch to stdout then calls Application.Quit(1); in non-batch mode it throws.

Common situations: Version bumped in package.json but the CI pipeline's UNITY_PACKAGE_VERSION env var was not updated to match. Or the env var is sourced from a git tag / CI variable while package.json still holds the old version. A release script that updates one but not the other.


AI-assisted analysis of Cysharp/UniTask@ceac8d6946 (2026-08-13). Data as JSON: /api/errors/9279677f40f5a739. Report an issue: GitHub.