Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating @nx/angular:library with the name parameter fails with an error - The selector is invalid. #29229

Closed
1 of 4 tasks
Fafnur opened this issue Dec 6, 2024 · 1 comment · Fixed by #29417
Closed
1 of 4 tasks
Assignees
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug

Comments

@Fafnur
Copy link

Fafnur commented Dec 6, 2024

Current Behavior

You will get an error if you try to generate an Angular library with a name that includes a slash.

Try run:

yarn nx g @nx/angular:library libs/auth/common --name=auth/common

Image

The issue lies with the selector name.

Error: The selector "lib-auth/common" is invalid.

Expected Behavior

It is expected that a library should be created when a slash is included in its name.

The Nx command should handle slashes by replacing them with dashes in selectors.

GitHub Repo

https://github.com/Fafnur/nx-20-angular-lib-generation

Steps to Reproduce

  1. Generate a new workspace with angular
yarn create nx-workspace nx-20-angular-lib-generation
  1. Try generate aan Angular library with a name that includes a slash: 'auth/common'
yarn nx g @nx/angular:library libs/auth/common --name=auth/common

Nx Report

Node           : 22.11.0
OS             : linux-x64
Native Target  : x86_64-linux
npm            : 10.9.0

nx                 : 20.2.0
@nx/js             : 20.2.0
@nx/jest           : 20.2.0
@nx/eslint         : 20.2.0
@nx/workspace      : 20.2.0
@nx/angular        : 20.2.0
@nx/devkit         : 20.2.0
@nx/eslint-plugin  : 20.2.0
@nx/web            : 20.2.0
@nx/webpack        : 20.2.0
typescript         : 5.6.3
---------------------------------------
Community plugins:
angular-eslint : 19.0.1

Failure Logs

NX   The selector "lib-auth/common" is invalid.

Error: The selector "lib-auth/common" is invalid.
    at validateHtmlSelector (/mnt/Storage/Development/angular/nx-20-angular-lib-generation/node_modules/@nx/angular/src/generators/utils/selector.js:18:15)
    at normalizeOptions (/mnt/Storage/Development/angular/nx-20-angular-lib-generation/node_modules/@nx/angular/src/generators/component/lib/normalize-options.js:21:41)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async componentGenerator (/mnt/Storage/Development/angular/nx-20-angular-lib-generation/node_modules/@nx/angular/src/generators/component/component.js:9:21)
    at async addStandaloneComponent (/mnt/Storage/Development/angular/nx-20-angular-lib-generation/node_modules/@nx/angular/src/generators/library/lib/add-standalone-component.js:9:5)
    at async libraryGenerator (/mnt/Storage/Development/angular/nx-20-angular-lib-generation/node_modules/@nx/angular/src/generators/library/library.js:62:9)
    at async /mnt/Storage/Development/angular/nx-20-angular-lib-generation/node_modules/nx/src/command-line/generate/generate.js:240:26
    at async handleErrors (/mnt/Storage/Development/angular/nx-20-angular-lib-generation/node_modules/nx/src/utils/handle-errors.js:8:24)
    at async Object.handler (/mnt/Storage/Development/angular/nx-20-angular-lib-generation/node_modules/nx/src/command-line/generate/command-object.js:13:22)

Package Manager Version

1.22.22

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@Coly010 Coly010 self-assigned this Dec 6, 2024
@Fafnur Fafnur changed the title Generating @nx/angular:library with the name parameter fails with an error - Еhe selector is invalid. Generating @nx/angular:library with the name parameter fails with an error - The selector is invalid. Dec 7, 2024
@leosvelperez leosvelperez added the scope: angular Issues related to Angular support in Nx label Dec 9, 2024
Coly010 added a commit that referenced this issue Dec 19, 2024
## Current Behavior
When passing a project name with a `/` in it to the library generator,
this name passes through to the `component` generator.
The `component` generator may then attempt to build a selector from this
name, however, it does not normalize the `/`.

## Expected Behavior
Ensure the `/` is normalized from the name when building the selector

## Related Issue(s)

Fixes #29229
ndcunningham pushed a commit that referenced this issue Dec 20, 2024
## Current Behavior
When passing a project name with a `/` in it to the library generator,
this name passes through to the `component` generator.
The `component` generator may then attempt to build a selector from this
name, however, it does not normalize the `/`.

## Expected Behavior
Ensure the `/` is normalized from the name when building the selector

## Related Issue(s)

Fixes #29229
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants