nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.26k stars 2.32k forks source link

nx > 17 does not pass through cli npm arguments #26537

Open gkamperis opened 3 months ago

gkamperis commented 3 months ago

Current Behavior

npm run start -- --project=my-app the --project arg is not passed through

if nx.json has a defaultProject defined it will be run instead but if not then get the error

NX Both project and target have to be specified

Expected Behavior

all args should pass through - worked with v17

GitHub Repo

https://github.com/gkamperis/nx-incremental-bug

Steps to Reproduce

  1. checkout the repo
  2. npm run start -- --project=my-app

Nx Report

NX   Report complete - copy this into the issue template

Node   : 22.2.0
OS     : win32-x64
npm    : 10.8.1

nx (global)        : 19.2.2
nx                 : 18.3.5
@nx/js             : 18.3.5
@nx/jest           : 18.3.5
@nx/linter         : 18.3.5
@nx/eslint         : 18.3.5
@nx/workspace      : 18.3.5
@nx/angular        : 18.3.5
@nx/devkit         : 18.3.5
@nx/eslint-plugin  : 18.3.5
@nrwl/tao          : 18.3.5
@nx/web            : 18.3.5
@nx/webpack        : 18.3.5
typescript         : 5.4.5

Failure Logs

No response

Package Manager Version

No response

Operating System

Additional Information

No response

elevenpassin commented 3 months ago

I tried to test this locally, but I was unfortunately not able to replicate this locally. As you can see from below logs, I was able to get the correct project running by using the --project option. I did add the defaultProject too here to nx graph

my-app

D:\Development\github\nx-exp\nx-incremental-bug on  λ npm run start -- --project=my-app

> @nx19/source@0.0.0 start
> nx serve --project=my-app

> nx run my-app:serve:development

- Generating browser application bundles (phase: setup)...
✔ Browser application bundle generation complete.

Initial chunk files   | Names         |  Raw size
vendor.js             | vendor        |   2.85 MB | 
polyfills.js          | polyfills     | 345.88 kB | 
styles.css, styles.js | styles        | 233.53 kB | 
main.js               | main          |  47.19 kB | 
runtime.js            | runtime       |   6.67 kB | 

                      | Initial total |   3.49 MB

Build at: 2024-06-13T20:02:37.611Z - Hash: b0f3c2a24dd91650 - Time: 21630ms

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

√ Compiled successfully.

my-app-m

D:\Development\github\nx-exp\nx-incremental-bug on  λ npm run start -- --project=my-app-m

> @nx19/source@0.0.0 start
> nx serve --project=my-app-m

> nx run my-app-m:serve:development

- Generating browser application bundles (phase: setup)...
 NX   Running target build for project my-lib:
- my-lib
> nx run my-lib:build:production
Building Angular Package

------------------------------------------------------------------------------
Building entry point '@nx19/my-lib'
------------------------------------------------------------------------------
- Compiling with Angular sources in Ivy full compilation mode.
✔ Compiling with Angular sources in Ivy full compilation mode.
Copying assets
Writing package manifest
Built @nx19/my-lib

------------------------------------------------------------------------------
Built Angular Package
 - from: D:\Development\github\nx-exp\nx-incremental-bug\libs\my-lib
 - to:   D:\Development\github\nx-exp\nx-incremental-bug\dist\libs\my-lib
------------------------------------------------------------------------------

Build at: 2024-06-13T20:14:31.930Z - Time: 1498ms

 NX   Successfully ran target build for project my-lib
✔ Browser application bundle generation complete.

Initial chunk files   | Names         |  Raw size
vendor.js             | vendor        |   2.85 MB | 
polyfills.js          | polyfills     | 345.88 kB | 
styles.css, styles.js | styles        | 233.55 kB | 
main.js               | main          |  52.25 kB | 
runtime.js            | runtime       |   6.67 kB | 

                      | Initial total |   3.49 MB

Build at: 2024-06-13T20:14:39.033Z - Hash: 1a9c089bf2e8c00b - Time: 10213ms

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

√ Compiled successfully.
✔ Browser application bundle generation complete.

Initial chunk files | Names   | Raw size
main.js             | main    | 52.25 kB | 
runtime.js          | runtime |  6.67 kB | 

3 unchanged chunks

Build at: 2024-06-13T20:14:39.426Z - Hash: 6b6b10dffdbc54cc - Time: 245ms

√ Compiled successfully.

It could definitely just be me but here's the steps I did:

gkamperis commented 3 months ago

hi @elevenpassin thanks for trying this out.

defaultProject is not required. why did you add it? removing it makes some commands throw which is something that needs to be looked at on its own right. having it there masks the issue of the missing project and it proved a stealthy issue for us.

I did some further tests because before reporting I tried this in 3 different environments:

in all cases I could not get to run the required project.

I realized that you might be using a different terminal app. So I tried more things...

Windows at home - windows terminal - powershell does not work Windows at home - cmd - works Windows at work- windows terminal - powershell does not work Windows at work - cmd - does not work Linux CI - Jenkins - does not work EDIT: in CI the workspace is created from scratch - no previous caching is at play

I also reinstalled everything - made sure global and repo Nx versions match - stopped daemon and nx reset.

Can you give another try with windows terminal/powershell?

Thanks in advance...

gkamperis commented 1 month ago

any updates on this? does this work on linux/CI ?

AgentEnder commented 1 month ago

Passing --project was never intended to be a form of specifying which project to run a given target for. Nx supports two forms, intentionally and as documented:

Substituting in build and myapp, that would be:

Is there a reason that either of these will not fit your use case? I recognize that the change here isn't great, but it wasn't an intended way to run things rather a side effect of previous implementation. If either of these options does not work for you we can revisit depending on the use case.

gkamperis commented 1 month ago

hi @AgentEnder thanks for the reply.

As reported v17 works fine. We have been using Nx since version 4! and it has always worked like this. I do not understand when you say it was never intended to specify the project.

To me it looks like you moved away from it without actually stressing that this is no longer supported. Are there migration docs for this deprecation?

how can we replicate specifying the project similar to the old style npm run myscript -- --project=myapp ? (myscript calls nx amongst other things)

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because more information has not been provided within 7 days. It will be closed in 21 days if no information is provided. If information has been provided, please reply to keep it active. Thanks for being a part of the Nx community! 🙏

gkamperis commented 1 month ago

keep alive

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because more information has not been provided within 7 days. It will be closed in 21 days if no information is provided. If information has been provided, please reply to keep it active. Thanks for being a part of the Nx community! 🙏

gkamperis commented 3 weeks ago

bump

github-actions[bot] commented 2 weeks ago

This issue has been automatically marked as stale because more information has not been provided within 7 days. It will be closed in 21 days if no information is provided. If information has been provided, please reply to keep it active. Thanks for being a part of the Nx community! 🙏

gkamperis commented 2 weeks ago

bump

github-actions[bot] commented 1 week ago

This issue has been automatically marked as stale because more information has not been provided within 7 days. It will be closed in 21 days if no information is provided. If information has been provided, please reply to keep it active. Thanks for being a part of the Nx community! 🙏

gkamperis commented 1 week ago

bump

github-actions[bot] commented 2 days ago

This issue has been automatically marked as stale because more information has not been provided within 7 days. It will be closed in 21 days if no information is provided. If information has been provided, please reply to keep it active. Thanks for being a part of the Nx community! 🙏

gkamperis commented 2 days ago

yet another bump