nx icon indicating copy to clipboard operation
nx copied to clipboard

npx nx@latest init failes on empty Git Repo Folder

Open dmlang opened this issue 1 year ago • 5 comments

Current Behavior

npx nx@latest init failes with "Error: Both project and target have to be specified"

Expected Behavior

Init NX inside an empty Git repo folder

GitHub Repo

No response

Steps to Reproduce

  1. npx nx@latest init on an emtpy git folder

Nx Report

Node   : 20.7.0
OS     : darwin-arm64
npm    : 10.1.0

nx (global)  : 18.0.3
nx           : 18.0.4
@nrwl/tao    : 18.0.4

Failure Logs

Setting Nx up installation in `.nx`. You can run Nx commands like: `./nx --help`
CREATE nx.json
UPDATE .gitignore
CREATE .nx/nxw.js
CREATE nx.bat
CREATE nx
Smart Monorepos · Fast CI

Commands:
  nx add <packageSpecifier>                        Install a plugin and initialize it.
  nx affected                                      Run target for affected projects
  nx affected:graph                                Graph dependencies affected by changes  [aliases: affected:dep-graph] [deprecated: Use `nx graph --affected`, or `nx affected --graph` instead depending on which best suits your use case. The `affected:graph` command will be removed in Nx 19.]
  nx connect                                       Connect workspace to Nx Cloud  [aliases: connect-to-nx-cloud]
  nx daemon                                        Prints information about the Nx Daemon process or starts a daemon process
  nx graph                                         Graph dependencies within workspace  [aliases: dep-graph]
  nx exec                                          Executes any command as if it was a target on the project
  nx format:check                                  Check for un-formatted files
  nx format:write                                  Overwrite un-formatted files  [aliases: format]
  nx generate <generator> [_..]                    Generate or update source code (e.g., nx generate @nx/js:lib mylib).  [aliases: g]
  nx init                                          Adds Nx to any type of workspace. It installs nx, creates an nx.json configuration file and optionally sets up remote caching. For more info, check https://nx.dev/recipes/adopting-nx.
  nx list [plugin]                                 Lists installed plugins, capabilities of installed plugins and other available plugins.
  nx migrate [packageAndVersion]                   Creates a migrations file or runs migrations from the migrations file.
                                                     - Migrate packages and create migrations.json (e.g., nx migrate @nx/workspace@latest)
                                                     - Run migrations (e.g., nx migrate --run-migrations=migrations.json). Use flag --if-exists to run migrations only if the migrations file exists.
  nx print-affected                                Prints information about the projects and targets affected by changes  [deprecated: Use `nx show projects --affected`, `nx affected --graph -t build` or `nx graph --affected` depending on which best suits your use case. The `print-affected` command will be removed in Nx 19.]
  nx release                                       **ALPHA**: Orchestrate versioning and publishing of applications and libraries
  nx repair                                        Repair any configuration that is no longer supported by Nx.

                                                       Specifically, this will run every migration within the `nx` package
                                                       against the current repository. Doing so should fix any configuration
                                                       details left behind if the repository was previously updated to a new
                                                       Nx version without using `nx migrate`.

                                                       If your repository has only ever updated to newer versions of Nx with
                                                       `nx migrate`, running `nx repair` should do nothing.

  nx report                                        Reports useful version numbers to copy into the Nx issue template
  nx reset                                         Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.  [aliases: clear-cache]
  nx run [project][:target][:configuration] [_..]  Run a target for a project
                                                       (e.g., nx run myapp:serve:production).

                                                       You can also use the infix notation to run a target:
                                                       (e.g., nx serve myapp --configuration=production)

                                                       You can skip the use of Nx cache by using the --skip-nx-cache option.
  nx run-many                                      Run target for multiple listed projects
  nx show                                          Show information about the workspace (e.g., list of projects)
  nx view-logs                                     Enables you to view and interact with the logs via the advanced analytic UI from Nx Cloud to help you debug your issue. To do this, Nx needs to connect your workspace to Nx Cloud and upload the most recent run details. Only the metrics are uploaded, not the artefacts.
  nx watch                                         Watch for changes within projects, and execute commands
  nx <target> [project] [_..]                      Run a target for a project  [default]

Options:
      --help            Show help  [boolean]
      --version         Show version number  [boolean]
      --batch           Run task(s) in batches for executors which support batches  [boolean] [default: false]
  -c, --configuration   This is the configuration to use when performing tasks on projects  [string]
      --output-style    Defines how Nx emits outputs tasks logs  [string] [choices: "dynamic", "static", "stream", "stream-without-prefixes", "compact"]
      --exclude         Exclude certain projects from being processed  [string]
      --parallel        Max number of parallel processes [default is 3]  [string]
      --runner          This is the name of the tasks runner configured in nx.json  [string]
      --graph           Show the task graph of the command. Pass a file path to save the graph data instead of viewing it in the browser.  [string]
      --verbose         Prints additional information about the commands (e.g., stack traces)  [boolean]
      --nxBail          Stop command execution after the first failed task  [boolean] [default: false]
      --nxIgnoreCycles  Ignore cycles in the task graph  [boolean] [default: false]
      --skipNxCache     Rerun the tasks even when the results are available in the cache  [boolean] [default: false]
      --project         Target project  [string]

Error: Both project and target have to be specified
    at parseRunOneOptions (/Users/dm/Work/projects/edurockers-mono/.nx/installation/node_modules/nx/src/command-line/run/run-one.js:99:15)
    at Object.runOne (/Users/dm/Work/projects/edurockers-mono/.nx/installation/node_modules/nx/src/command-line/run/run-one.js:22:18)
nx init

Adds Nx to any type of workspace. It installs nx, creates an nx.json configuration file and optionally sets up remote caching. For more info, check
https://nx.dev/recipes/adopting-nx.

Options:
  --help                  Show help                                                                                                                                         [boolean]
  --version               Show version number                                                                                                                               [boolean]
  --nxCloud               Set up distributed caching with Nx Cloud.                                                                                                         [boolean]
  --interactive           When false disables interactive input prompts for options.                                                                        [boolean] [default: true]
  --useDotNxInstallation  Initialize an Nx workspace setup in the .nx directory of the current repository.                                                 [boolean] [default: false]

Error: Command failed: ./nx
Smart Monorepos · Fast CI

Commands:
  nx add <packageSpecifier>                        Install a plugin and initialize it.
  nx affected                                      Run target for affected projects
  nx affected:graph                                Graph dependencies affected by changes  [aliases: affected:dep-graph] [deprecated: Use `nx graph --affected`, or `nx affected --graph` instead depending on which best suits your use case. The `affected:graph` command will be removed in Nx 19.]
  nx connect                                       Connect workspace to Nx Cloud  [aliases: connect-to-nx-cloud]
  nx daemon                                        Prints information about the Nx Daemon process or starts a daemon process
  nx graph                                         Graph dependencies within workspace  [aliases: dep-graph]
  nx exec                                          Executes any command as if it was a target on the project
  nx format:check                                  Check for un-formatted files
  nx format:write                                  Overwrite un-formatted files  [aliases: format]
  nx generate <generator> [_..]                    Generate or update source code (e.g., nx generate @nx/js:lib mylib).  [aliases: g]
  nx init                                          Adds Nx to any type of workspace. It installs nx, creates an nx.json configuration file and optionally sets up remote caching. For more info, check https://nx.dev/recipes/adopting-nx.
  nx list [plugin]                                 Lists installed plugins, capabilities of installed plugins and other available plugins.
  nx migrate [packageAndVersion]                   Creates a migrations file or runs migrations from the migrations file.
                                                     - Migrate packages and create migrations.json (e.g., nx migrate @nx/workspace@latest)
                                                     - Run migrations (e.g., nx migrate --run-migrations=migrations.json). Use flag --if-exists to run migrations only if the migrations file exists.
  nx print-affected                                Prints information about the projects and targets affected by changes  [deprecated: Use `nx show projects --affected`, `nx affected --graph -t build` or `nx graph --affected` depending on which best suits your use case. The `print-affected` command will be removed in Nx 19.]
  nx release                                       **ALPHA**: Orchestrate versioning and publishing of applications and libraries
  nx repair                                        Repair any configuration that is no longer supported by Nx.

                                                       Specifically, this will run every migration within the `nx` package
                                                       against the current repository. Doing so should fix any configuration
                                                       details left behind if the repository was previously updated to a new
                                                       Nx version without using `nx migrate`.

                                                       If your repository has only ever updated to newer versions of Nx with
                                                       `nx migrate`, running `nx repair` should do nothing.

  nx report                                        Reports useful version numbers to copy into the Nx issue template
  nx reset                                         Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.  [aliases: clear-cache]
  nx run [project][:target][:configuration] [_..]  Run a target for a project
                                                       (e.g., nx run myapp:serve:production).

                                                       You can also use the infix notation to run a target:
                                                       (e.g., nx serve myapp --configuration=production)

                                                       You can skip the use of Nx cache by using the --skip-nx-cache option.
  nx run-many                                      Run target for multiple listed projects
  nx show                                          Show information about the workspace (e.g., list of projects)
  nx view-logs                                     Enables you to view and interact with the logs via the advanced analytic UI from Nx Cloud to help you debug your issue. To do this, Nx needs to connect your workspace to Nx Cloud and upload the most recent run details. Only the metrics are uploaded, not the artefacts.
  nx watch                                         Watch for changes within projects, and execute commands
  nx <target> [project] [_..]                      Run a target for a project  [default]

Options:
      --help            Show help  [boolean]
      --version         Show version number  [boolean]
      --batch           Run task(s) in batches for executors which support batches  [boolean] [default: false]
  -c, --configuration   This is the configuration to use when performing tasks on projects  [string]
      --output-style    Defines how Nx emits outputs tasks logs  [string] [choices: "dynamic", "static", "stream", "stream-without-prefixes", "compact"]
      --exclude         Exclude certain projects from being processed  [string]
      --parallel        Max number of parallel processes [default is 3]  [string]
      --runner          This is the name of the tasks runner configured in nx.json  [string]
      --graph           Show the task graph of the command. Pass a file path to save the graph data instead of viewing it in the browser.  [string]
      --verbose         Prints additional information about the commands (e.g., stack traces)  [boolean]
      --nxBail          Stop command execution after the first failed task  [boolean] [default: false]
      --nxIgnoreCycles  Ignore cycles in the task graph  [boolean] [default: false]
      --skipNxCache     Rerun the tasks even when the results are available in the cache  [boolean] [default: false]
      --project         Target project  [string]

Error: Both project and target have to be specified
    at parseRunOneOptions (/Users/dm/Work/projects/edurockers-mono/.nx/installation/node_modules/nx/src/command-line/run/run-one.js:99:15)
    at Object.runOne (/Users/dm/Work/projects/edurockers-mono/.nx/installation/node_modules/nx/src/command-line/run/run-one.js:22:18)

    at checkExecSyncError (node:child_process:890:11)
    at execSync (node:child_process:962:15)
    at runNxSync (/Users/dm/.npm/_npx/f948e921c5898768/node_modules/nx/src/utils/child-process.js:25:34)
    at Object.initHandler (/Users/dm/.npm/_npx/f948e921c5898768/node_modules/nx/src/command-line/init/init-v2.js:34:39)
    at Object.handler (/Users/dm/.npm/_npx/f948e921c5898768/node_modules/nx/src/command-line/init/command-object.js:12:40)
    at /Users/dm/.npm/_npx/f948e921c5898768/node_modules/yargs/build/index.cjs:1:8993
    at j (/Users/dm/.npm/_npx/f948e921c5898768/node_modules/yargs/build/index.cjs:1:4956)
    at _.handleValidationAndGetResult (/Users/dm/.npm/_npx/f948e921c5898768/node_modules/yargs/build/index.cjs:1:8962)
    at _.applyMiddlewareAndGetResult (/Users/dm/.npm/_npx/f948e921c5898768/node_modules/yargs/build/index.cjs:1:9604) {
  status: 1,
  signal: null,
  output: [
    null,
    <Buffer 0a 61 64 64 65 64 20 31 31 39 20 70 61 63 6b 61 67 65 73 2c 20 61 6e 64 20 61 75 64 69 74 65 64 20 31 32 30 20 70 61 63 6b 61 67 65 73 20 69 6e 20 37 ... 93 more bytes>,
    <Buffer 53 6d 61 72 74 20 4d 6f 6e 6f 72 65 70 6f 73 20 c2 b7 20 46 61 73 74 20 43 49 0a 0a 43 6f 6d 6d 61 6e 64 73 3a 0a 20 20 6e 78 20 61 64 64 20 3c 70 61 ... 6511 more bytes>
  ],
  pid: 97292,
  stdout: <Buffer 0a 61 64 64 65 64 20 31 31 39 20 70 61 63 6b 61 67 65 73 2c 20 61 6e 64 20 61 75 64 69 74 65 64 20 31 32 30 20 70 61 63 6b 61 67 65 73 20 69 6e 20 37 ... 93 more bytes>,
  stderr: <Buffer 53 6d 61 72 74 20 4d 6f 6e 6f 72 65 70 6f 73 20 c2 b7 20 46 61 73 74 20 43 49 0a 0a 43 6f 6d 6d 61 6e 64 73 3a 0a 20 20 6e 78 20 61 64 64 20 3c 70 61 ... 6511 more bytes>

Package Manager Version

No response

Operating System

  • [X] macOS
  • [ ] Linux
  • [ ] Windows
  • [ ] Other (Please specify)

Additional Information

No response

dmlang avatar Feb 12 '24 18:02 dmlang

Same problem in a non-empty git repository. Trying to add nx to an existing project.

NX Report

 >  NX   Report complete - copy this into the issue template

   Node   : 18.14.1
   OS     : darwin-arm64
   npm    : 9.3.1

   nx (global)  : 17.1.3
   nx           : 18.0.4
   @nrwl/tao    : 18.0.4

Clindbergh avatar Feb 13 '24 09:02 Clindbergh

Also occurs when trying the latest beta:

npx [email protected] init                                                                                                                                  
~/r....
Need to install the following packages:
  [email protected]
Ok to proceed? (y)

and any other 18.* version. npx [email protected] init works fine.

Clindbergh avatar Feb 13 '24 09:02 Clindbergh

I have the same issue and I tried running npx [email protected] init and even npx [email protected] init thinking it was a workaround but not all files were generated this way and after running nx init again it defaults back to version 18.0.4 bringing me back to the error above.

>  NX   Report complete - copy this into the issue template

   Node   : 20.6.1
   OS     : win32-x64
   npm    : 9.8.1

   nx         : 18.0.4
   @nrwl/tao  : 18.0.4

Wurielle avatar Feb 13 '24 13:02 Wurielle

not all files were generated this way

What files were missing @Wurielle ?

I did the same followed by npx nx migrate latest and npx nx migrate --run-migrations successfully.

Clindbergh avatar Feb 13 '24 14:02 Clindbergh

I initially thought it would create some config files but I was wrong. nx migrate latest was enough to migrate to v18.0.4 and start a generator though so there are no more issues on my end, thank you.

Wurielle avatar Feb 13 '24 16:02 Wurielle

Cannot run migrations either.

femiojemuyiwa@FemiMacBook flex-pricing-ui % nx migrate latest --interactive --verbose Failed to install the latest version of the migration script. Using the current version. Fetching meta data about packages. It may take a few minutes. Fetching [email protected] Fetching [email protected]

NX The migrate command failed.

NX ENOENT: no such file or directory, open '/var/folders/jt/bynvsqwx6vqfz43zlv9nkw7c0000gn/T/tmp-18306-QotK87MXhEkF/package.json'

Error: ENOENT: no such file or directory, open '/var/folders/jt/bynvsqwx6vqfz43zlv9nkw7c0000gn/T/tmp-18306-QotK87MXhEkF/package.json' at writeFileSync (node:fs:2352:20) at writeJsonFile (/Users/femiojemuyiwa/Documents/EWE/flex-pricing/flex-pricing-ui/node_modules/nx/src/utils/fileutils.js:55:28) at createTempNpmDirectory (/Users/femiojemuyiwa/Documents/EWE/flex-pricing/flex-pricing-ui/node_modules/nx/src/utils/package-manager.js:214:35) at getPackageMigrationsUsingInstall (/Users/femiojemuyiwa/Documents/EWE/flex-pricing/flex-pricing-ui/node_modules/nx/src/command-line/migrate/migrate.js:621:75) at /Users/femiojemuyiwa/Documents/EWE/flex-pricing/flex-pricing-ui/node_modules/nx/src/command-line/migrate/migrate.js:541:20 at async Migrator.populatePackageJsonUpdatesAndGetPackagesToCheck (/Users/femiojemuyiwa/Documents/EWE/flex-pricing/flex-pricing-ui/node_modules/nx/src/command-line/migrate/migrate.js:142:31) at async Migrator.buildPackageJsonUpdates (/Users/femiojemuyiwa/Documents/EWE/flex-pricing/flex-pricing-ui/node_modules/nx/src/command-line/migrate/migrate.js:112:33) at async Migrator.migrate (/Users/femiojemuyiwa/Documents/EWE/flex-pricing/flex-pricing-ui/node_modules/nx/src/command-line/migrate/migrate.js:78:9) at async generateMigrationsJsonAndUpdatePackageJson (/Users/femiojemuyiwa/Documents/EWE/flex-pricing/flex-pricing-ui/node_modules/nx/src/command-line/migrate/migrate.js:772:78) at async /Users/femiojemuyiwa/Documents/EWE/flex-pricing/flex-pricing-ui/node_modules/nx/src/command-line/migrate/migrate.js:1020:13 Command failed: npx nx _migrate latest --interactive --verbose

ojemuyiwa avatar Feb 19 '24 13:02 ojemuyiwa

i tried with latest nx 19.0.4 by running npx nx@latest init in an empty folder, it works fine.

xiongemi avatar May 21 '24 20:05 xiongemi