abpframework/abp · error · CliUsageException

Angular library name can not be empty

Error message

Angular library name can not be empty

What it means

Thrown by ProjectCreationCommandBase.CreateAngularLibraryAsync when the libraryName parameter is null or whitespace. This method generates an Angular library using the ABP schematics (npx ng g @abp/ng.schematics:create-lib) and requires a valid package name. The code marks the validation with a TODO suggesting it could be improved.

Source

Thrown at framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs:796

        var libraryName = projectArgs.SolutionName.ProjectName.ToKebabCase();
        var angularAppPath = Path.Combine(rootPath, "apps", "angular");

        var result = await CreateAngularLibraryAsync(libraryName, angularAppPath);

        Logger.LogInformation(result);
    }

    protected virtual async Task<string> CreateAngularLibraryAsync(
        string libraryName,
        string workingDirectory,
        bool isSecondaryEndpoint = false,
        bool isModuleTemplate = true,
        bool isOverride = true)
    {
        //TODO: Can we improve this validations ?
        if (string.IsNullOrWhiteSpace(libraryName))
        {
            throw new CliUsageException("Angular library name can not be empty");
        }

        if (string.IsNullOrWhiteSpace(workingDirectory))
        {
            throw new CliUsageException("Angular project path can not be empty");
        }

        var commandBuilder = new StringBuilder($"npx ng g @abp/ng.schematics:create-lib --package-name {libraryName}");

        commandBuilder.Append($" --is-secondary-entrypoint {isSecondaryEndpoint.ToString().ToLowerInvariant()}");
        commandBuilder.Append($" --is-module-template {isModuleTemplate.ToString().ToLowerInvariant()}");
        commandBuilder.Append($" --override {isOverride.ToString().ToLowerInvariant()}");

        var result = CmdHelper.RunCmdAndGetOutput(commandBuilder.ToString(), workingDirectory);
        return await Task.FromResult(result);
    }

    public static class Options

View on GitHub (pinned to 7ed43b1931)

Solutions

  1. Ensure the module or entity name (from which the Angular library name is derived) is provided and non-empty
  2. Pass an explicit, non-empty library name that follows npm package naming conventions (e.g., @mycompany/my-lib)
  3. Check upstream: if the name comes from commandLineArgs.Target or a module parameter, ensure that was supplied

Example fix

// before
await CreateAngularLibraryAsync("", workingDir);

// after
await CreateAngularLibraryAsync("@mycompany/feature-lib", workingDir);
Defensive patterns

Strategy: validation

Validate before calling

// Validate the Angular library name before calling CreateAngularLibraryAsync
if (string.IsNullOrWhiteSpace(libraryName))
{
    Console.Error.WriteLine("Error: Angular library name cannot be empty. Derive it from the module name.");
    return;
}
// Also validate npm package name format
if (!Regex.IsMatch(libraryName, @"^(@[a-z0-9-~][a-z0-9-._~]*/)?[a-z0-9-~][a-z0-9-._~]*$"))
{
    Console.Error.WriteLine($"Error: '{libraryName}' is not a valid npm package name.");
    return;
}

Type guard

// Type guard for non-empty, npm-valid library name
static bool IsValidAngularLibraryName(string? name) =>
    !string.IsNullOrWhiteSpace(name) &&
    Regex.IsMatch(name, @"^(@[a-z0-9-~][a-z0-9-._~]*/)?[a-z0-9-~][a-z0-9-._~]*$");

Try / catch

try
{
    await CreateAngularLibraryAsync(libraryName, workingDirectory);
}
catch (CliUsageException ex) when (ex.Message.Contains("Angular library name can not be empty"))
{
    logger.LogError("Library name was empty. Ensure the module/entity name is provided.");
}

Prevention

When it happens

Trigger: Calling CreateAngularLibraryAsync with an empty/null library name. This typically happens when the caller derives the library name from a module or entity name that was not provided, or from a template variable that resolved to empty.

Common situations: During module template generation where the module/entity name is missing or empty, causing the derived Angular library name to be empty. Also from programmatic API misuse where the caller does not validate before invoking. The TODO comment indicates the validation is considered incomplete.

Related errors


AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13). Data as JSON: /api/errors/124279a5ab6e2d15. Report an issue: GitHub.