babalae/better-genshin-impact · error · Exception

manifest.json: version is required.

Error message

manifest.json: version is required.

What it means

Thrown by Manifest.Validate when the Version property is null, empty, or whitespace after deserialization. The manifest.json must contain a non-empty 'version' field. This is the second validation check, following the Name check.

Source

Thrown at BetterGenshinImpact/Core/Script/Project/Manifest.cs:46

    public string[] SavedFiles { get; set; } = [];
    public string[] HttpAllowedUrls { get; set; } = [];

    public static Manifest FromJson(string json)
    {
        var manifest = JsonSerializer.Deserialize<Manifest>(json, Global.ManifestJsonOptions) ?? throw new Exception("Failed to deserialize JSON.");
        return manifest;
    }

    public void Validate(string path)
    {
        if (string.IsNullOrWhiteSpace(Name))
        {
            throw new Exception("manifest.json: name is required.");
        }

        if (string.IsNullOrWhiteSpace(Version))
        {
            throw new Exception("manifest.json: version is required.");
        }

        if (string.IsNullOrWhiteSpace(Main))
        {
            throw new Exception("manifest.json: main script is required.");
        }

        if (!File.Exists(Path.Combine(path, Main)))
        {
            throw new FileNotFoundException("main js file not found.");
        }

        // 比较版本号大小 BgiVersion
        if (!string.IsNullOrWhiteSpace(BgiVersion) && Global.IsNewVersion(BgiVersion))
        {
            TaskControl.Logger.LogError("脚本 {Name} 版本号要求 {BgiVersion} 大于当前 BetterGI 版本号 {CurrentVersion} , 脚本可能无法正常工作,请更新 BetterGI 版本!", Name, BgiVersion, Global.Version);
        }
    }

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Open manifest.json and add a 'version' field: "version": "1.0.0".
  2. Follow semantic versioning (semver) format for the version string.
  3. Use a complete manifest template when creating new scripts.

Example fix

// manifest.json before
{ "name": "my-script", "main": "main.js" }
// after
{ "name": "my-script", "version": "1.0.0", "main": "main.js" }
Defensive patterns

Strategy: validation

Validate before calling

var manifest = Manifest.FromJson(json);
if (string.IsNullOrWhiteSpace(manifest.Version))
    throw new InvalidOperationException("manifest.json must have a non-empty 'version' field");

Try / catch

try
{
    manifest.Validate(projectPath);
}
catch (Exception ex) when (ex.Message.Contains("version is required"))
{
    TaskControl.Logger.LogError("Script manifest missing version field");
}

Prevention

When it happens

Trigger: Loading a script project whose manifest.json is missing the 'version' field or has it set to null/empty/whitespace. Manifest.Validate(path) is called from the ScriptProject constructor.

Common situations: A script package template omitted the version field. The version was manually deleted during editing. Migrating from an older manifest format that didn't require version.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/c54ff7bd9bbdbc94. Report an issue: GitHub.