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

Local workspace-generator does not work after update to nx@15.0.0 #12677

Closed
bridzius opened this issue Oct 18, 2022 · 10 comments · Fixed by #12821 or #12955
Closed

Local workspace-generator does not work after update to nx@15.0.0 #12677

bridzius opened this issue Oct 18, 2022 · 10 comments · Fixed by #12821 or #12955
Assignees
Labels
community This is a good first issue for contributing outdated scope: devkit type: bug

Comments

@bridzius
Copy link

bridzius commented Oct 18, 2022

Current Behavior

npx nx workspace-generator <name> <options> fails with

Not enough non-option arguments: got 0, need at least 1

The error happens due to a recent change in nx, where (option) is appended to the command if there are options specified.

Converting https://github.com/nrwl/nx/blob/master/packages/nx/src/command-line/nx-commands.ts#L841
from if(options.length) to if(!options.length) seems to fix the issue.
I can try creating a PR if that helps.

Expected Behavior

npx nx workspace-generator <name> <options> should launch the generator and generate the required code.

Steps to Reproduce

Reproduction in https://github.com/bridzius/workspace-generator-repro
Clone, npm ci, run npx nx workspace-generator generato --all. Should run the generator, but fails with said error.

Failure Logs

npx nx workspace-generator generato --all
nx workspace-generator generato [name] (options)

Positionals:
  name  Library name                                                                                              [string]

Options:
  --help     Show help                                                                                           [boolean]
  --version  Show version number                                                                                 [boolean]
  --all      All for testing                                                                                     [boolean]

Find more information and examples at https://nx.dev/nx/workspace-generator

Not enough non-option arguments: got 0, need at least 1

Environment

   Node : 16.17.1
   OS   : darwin arm64
   npm  : 8.15.0
   nx : 15.0.0
   @nrwl/angular : 15.0.0
   @nrwl/cypress : 15.0.0
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.0.0
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.0.0
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.0.0
   @nrwl/js : 15.0.0
   @nrwl/linter : 15.0.0
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 15.0.0
   @nrwl/web : Not Found
   @nrwl/webpack : 15.0.0
   @nrwl/workspace : 15.0.0
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:
@FrozenPandaz
Copy link
Collaborator

Workspace generators is configured by default to require a name.
https://github.com/bridzius/workspace-generator-repro/blob/main/tools/generators/generato/schema.json#L20

If you run the following, it will work:

npx nx workspace-generator generato my-name-here --all

The error isn't the greatest but we can fix this.

I think a better error would be the following?

 NX   Required property 'name' is missing.

@FrozenPandaz FrozenPandaz reopened this Oct 18, 2022
@FrozenPandaz FrozenPandaz added scope: devkit community This is a good first issue for contributing labels Oct 18, 2022
@bridzius
Copy link
Author

bridzius commented Oct 18, 2022

@FrozenPandaz, thank you for the answer and you are completely right - this was an error on my part when creating the repro.
Updated the repro by removing the "name" from the schema.

When creating a generator manually - the "name" property might not be specified, which ends up with the previous error.

Does this mean that the name is now (since 15) a required property regardless of the schema and should be added to all workspace-generators?

For our uses, we don't have a name property, since have separate workspace-generators for separate use cases.
EDIT: probably an example is in order. In our use cases, the generator itself is the name, so we run
npx nx workspace-generator <generator-name> <options>
rather than
npx nx workspace-generator <generator-name> <name> <options>
Does this mean that the former one is no longer a valid option?

@Hotell
Copy link
Contributor

Hotell commented Oct 19, 2022

Workspace generators is configured by default to require a name.

Would you mind to elaborate more on this one @FrozenPandaz ? There is no mention of such a thing in docs nor release changelog.

Anyways workspace generator execution is indeed broken in nx 15 (it has nothing to do with missing name ).

image

Last workable state Nx 14.8.4 (its broken since 14.8.5 -> #12258)

ping @meeroslav

image

@ShiJuuRoku
Copy link

I have same issue here.
No required params is specified.

{
  "$schema": "http://json-schema.org/schema",
  "cli": "nx",
  "$id": "app-generator",
  "type": "object",
  "properties": {
    "target": {
      "type": "string",
      "description": "Target Project name",
      "$default": {
        "$source": "argv",
        "index": 0
      }
    }
  }
}

@ild0tt0re
Copy link

ild0tt0re commented Oct 25, 2022

We have the same issue on Nx v14.8.6

@Roozenboom
Copy link
Contributor

Roozenboom commented Oct 25, 2022

We have exactly the same error after upgrading to NX 15.0.1 (from 14.8.2) and after removing the following lines from packages/nx/src/command-line/nx-commands.ts L842 it worked again.

if (options.length) {
    command += ' (options)';
}

We also have another issue with local workspace-generators that has no properties object in the schema.json, because of missing error handling it throws the following error: TypeError: Cannot convert undefined or null to object for Object.entries(schema.properties).forEach(([name, prop]) => { as a workaround I can add an empty properties object to each schema.json but this can be fixed by checking if the property exists on packages/nx/src/command-line/nx-commands.ts L814.

I am happy to raise a pull request for both issues.

@YegorMedvedev
Copy link

Seems that it isn't working since ver 14.8.5
Instead of asking questions in the terminal, it fails with an error:

Not enough non-option arguments

@stomvi
Copy link

stomvi commented Nov 2, 2022

Same here.

@meeroslav
Copy link
Contributor

Sorry folks for this issue.

As @bridzius found out, the missing name is actually the generator name. The error message is a generic one and comes from the yargs we now use for automating help messages for your generators.

The issue that @Hotell found comes from invalid yargs command automation that unfortunately expects you to pass all mandatory values as positional (e.g. my-generator my-name) instead of flags (e.g. my-generator --name=my-name).

I'll get to it asap.

@github-actions
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 Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community This is a good first issue for contributing outdated scope: devkit type: bug
Projects
None yet
9 participants