{"record":{"id":"9279677f40f5a739","repo":"Cysharp/UniTask","slug":"package-json-and-env-version-are-mismatched","errorCode":null,"errorMessage":"package.json and env version are mismatched.","messagePattern":"package\\.json and env version are mismatched\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/UniTask/Assets/Editor/PackageExporter.cs","lineNumber":57,"sourceCode":"        var versionJson = Path.Combine(Application.dataPath, root, \"package.json\");\n\n        if (File.Exists(versionJson))\n        {\n            var v = JsonUtility.FromJson<Version>(File.ReadAllText(versionJson));\n\n            if (!string.IsNullOrEmpty(version))\n            {\n                if (v.version != version)\n                {\n                    var msg = $\"package.json and env version are mismatched. UNITY_PACKAGE_VERSION:{version}, package.json:{v.version}\";\n\n                    if (Application.isBatchMode)\n                    {\n                        Console.WriteLine(msg);\n                        Application.Quit(1);\n                    }\n\n                    throw new Exception(\"package.json and env version are mismatched.\");\n                }\n            }\n\n            version = v.version;\n        }\n\n        return version;\n    }\n\n    public class Version\n    {\n        public string version;\n    }\n}\n\n#endif","sourceCodeStart":39,"sourceCodeEnd":73,"githubUrl":"https://github.com/Cysharp/UniTask/blob/ceac8d6946b1125fe782cd171fbcb245b567dbf9/src/UniTask/Assets/Editor/PackageExporter.cs#L39-L73","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","If driving versions from CI, ensure the same step that sets UNITY_PACKAGE_VERSION also patches package.json before invoking Unity.","If package.json should be the single source of truth, unset UNITY_PACKAGE_VERSION from the environment so the check is skipped entirely.","Verify there are no leading/trailing whitespace or 'v' prefix mismatches between the two values."],"exampleFix":"// before: package.json has \"version\":\"2.5.1\" but CI sets:\n//   UNITY_PACKAGE_VERSION=2.3.0\n// after: align them\n//   UNITY_PACKAGE_VERSION=2.5.1","handlingStrategy":"validation","validationCode":"// Before running the export, verify versions match\nvar envVersion = Environment.GetEnvironmentVariable(\"UNITY_PACKAGE_VERSION\");\nif (!string.IsNullOrEmpty(envVersion))\n{\n    var pkg = JsonUtility.FromJson<Version>(File.ReadAllText(\"package.json\"));\n    if (pkg.version != envVersion)\n        throw new InvalidOperationException($\"Version mismatch: env={envVersion}, package.json={pkg.version}\");\n}\n// Shell alternative for CI:\n//   PKG=$(jq -r .version package.json)\n//   if [ -n \"$UNITY_PACKAGE_VERSION\" ] && [ \"$UNITY_PACKAGE_VERSION\" != \"$PKG\" ]; then\n//     echo \"Set UNITY_PACKAGE_VERSION=$PKG\"; exit 1\n//   fi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Maintain a single source of truth for the version — drive both package.json and UNITY_PACKAGE_VERSION from one variable in your release script.","Add a pre-build CI step that fails fast if the two disagree, before invoking Unity.","Use a release tool (e.g., semantic-release) that updates package.json and sets the env var atomically."],"tags":["ci-cd","build","versioning","unity-editor","package-export"],"backgroundTag":null,"analyzedSha":"ceac8d6946b1125fe782cd171fbcb245b567dbf9","analyzedAt":"2026-08-13T19:16:39.025Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}