babalae/better-genshin-impact · error · Exception

manifest.json: main script is required.

Error message

manifest.json: main script is required.

What it means

Thrown by Manifest.Validate when the Main property (entry-point script filename) is null, empty, or whitespace after deserialization. The manifest.json must specify a main JS file that serves as the script entry point. This is the third validation check.

Source

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

        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);
        }
    }

    public List<SettingItem> LoadSettingItems(string path)
    {
        if (string.IsNullOrWhiteSpace(SettingsUi))
        {

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Open manifest.json and add a 'main' field pointing to the entry JS file: "main": "main.js".
  2. Ensure the main field value is a relative filename, not an absolute path.
  3. Verify the referenced file actually exists (a subsequent check validates file existence).

Example fix

// manifest.json before
{ "name": "my-script", "version": "1.0.0" }
// 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.Main))
    throw new InvalidOperationException("manifest.json must have a non-empty 'main' field");

Try / catch

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

Prevention

When it happens

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

Common situations: A script package was created without specifying the entry-point file. The main field was accidentally removed during editing. Incomplete manifest from a broken packaging process.

Related errors


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