Skip to content

React library generator doesn't work using --routing flag #30721

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

Closed
1 of 4 tasks
manuelbosi opened this issue Apr 14, 2025 · 1 comment · Fixed by #31328 · May be fixed by #30722
Closed
1 of 4 tasks

React library generator doesn't work using --routing flag #30721

manuelbosi opened this issue Apr 14, 2025 · 1 comment · Fixed by #31328 · May be fixed by #30722
Assignees
Labels
priority: medium Medium Priority (not high, not low priority) scope: react Issues related to React support for Nx type: bug

Comments

@manuelbosi
Copy link

Current Behavior

Generating a new react library doesn't work if routing flag is set to true.

Expected Behavior

React library generator should work using the --routing=true flag

GitHub Repo

No response

Steps to Reproduce

  1. Create new nx project: pnpm dlx create-nx-workspace --pm pnpm
  2. Add @nx/react package: pnpm nx add @nx/react
  3. Generate a react library: pnpm nx g @nx/react:library --directory=packages/my-react-lib --name=my-react-lib --routing=true --no-interactive --dry-run
  4. The command will fails

Nx Report

NX   Report complete - copy this into the issue template

Node           : 22.13.1
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 10.8.0

nx                     : 20.7.2
@nx/js                 : 20.7.2
@nx/eslint             : 20.7.2
@nx/workspace          : 20.7.2
@nx/devkit             : 20.7.2
@nx/eslint-plugin      : 20.7.2
@nx/module-federation  : 20.7.2
@nx/react              : 20.7.2
@nx/vite               : 20.7.2
@nx/web                : 20.7.2
typescript             : 5.7.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/eslint/plugin
@nx/react/router-plugin
---------------------------------------
Cache Usage: 195.29 KB / 92.64 GB

Failure Logs

pnpm nx g @nx/react:library --directory=packages/my-react-lib --name=my-react-lib --routing=true --no-interactive --dry-run

 NX  Generating @nx/react:library

Error in node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_@swc+_b4a36daeda0a39830e1b1fa2cefb5f75/node_modules/@nx/react/src/generators/component/files/__fileName__.__ext__:

 NX   /node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_@swc+_b4a36daeda0a39830e1b1fa2cefb5f75/node_modules/@nx/react/src/generators/component/files/__fileName__.__ext__:56

    54| <%_ if (routing) { _%>
    55|         <ul>
 >> 56|           <li><Link to="/"><%= name %> root</Link></li>
    57|         </ul>
    58|         <Route path="/" element={<div>This is the <%= name %> root route.</div>} />
    59| <%_ } _%>

name is not defined
Pass --verbose to see the stacktrace.

Package Manager Version

No response

Operating System

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

Additional Information

No response

@FrozenPandaz FrozenPandaz added priority: medium Medium Priority (not high, not low priority) scope: react Issues related to React support for Nx labels Apr 14, 2025
manuelbosi added a commit to manuelbosi/nx that referenced this issue Apr 14, 2025
manuelbosi added a commit to manuelbosi/nx that referenced this issue Apr 27, 2025
manuelbosi added a commit to manuelbosi/nx that referenced this issue May 1, 2025
ndcunningham added a commit that referenced this issue May 26, 2025
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
When we try to generate a library with react it fails because `name` is
required.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
This should work out of the box.
## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #30721
@manuelbosi
Copy link
Author

Hi @ndcunningham, just for the next time, can you explain what's wrong with my PR #30722?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium Medium Priority (not high, not low priority) scope: react Issues related to React support for Nx type: bug
Projects
None yet
3 participants