nrwl / nx

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

Nx failing with new create-nx-workspace@17.1.1 for Angular #20199

Closed soumyanildas closed 10 months ago

soumyanildas commented 10 months ago

Current Behavior

Steps I used -

npx create-nx-workspace@latest nx-17-demo

NX Let's create a new workspace [https://nx.dev/getting-started/intro]

✔ Which stack do you want to use? · angular ✔ Integrated monorepo, or standalone project? · standalone ✔ Which bundler would you like to use? · esbuild ✔ Default stylesheet format · scss ✔ Do you want to enable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering)? · No

✔ Test runner to use for end to end (E2E) tests · cypress ✔ Enable distributed caching to make your CI faster · Yes

Get this error -

✔ Installing dependencies with npm
✖ Creating your workspace in nx-17-demo

  NX   Failed to create a workspace.

   Exit code: 1
   Log file: /var/folders/13/d4h_9bvx36z898g46r3tf34h0000gn/T/tmp-86849-gum5lRx7j3LJ/error.log

Expected Behavior

Should create workspace

GitHub Repo

No response

Steps to Reproduce

  1. npx create-nx-workspace@latest nx-17-demo

Nx Report

>  NX   Report complete - copy this into the issue template

   Node   : 18.17.1
   OS     : darwin-x64
   npm    : 9.6.7

   nx (global)    : 17.0.2
   nx             : 17.1.1
   @nx/js         : 17.1.1
   @nx/jest       : 17.1.1
   @nx/linter     : 17.1.1
   @nx/eslint     : 17.1.1
   @nx/workspace  : 17.1.1
   @nx/angular    : 17.1.1
   @nx/cypress    : 17.1.1
   @nx/devkit     : 17.1.1
   @nrwl/tao      : 17.1.1
   @nx/web        : 17.1.1
   @nx/webpack    : 17.1.1
   typescript     : 5.2.2


### Failure Logs

added 941 packages, and audited 942 packages in 12s

120 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

>  NX  Generating @nx/workspace:preset

 >  NX   The "--prefix" option was not provided, therefore attempted to use the "npmScope" defined in "nx.json" to set the application's selector prefix, but it is invalid.

   There are two options that can be followed to resolve this issue:
     - Pass a valid "--prefix" option.
     - Update the "npmScope" in "nx.json" (Note: this can be an involved process, as other libraries and applications may need to be updated to match the new scope).

   If you encountered this error when creating a new Nx Workspace, the workspace name or "npmScope" is invalid to use as the selector prefix for the application being generated.

   Valid selector prefixes must start with a letter, and must contain only alphanumeric characters or dashes.
   Pass --verbose to see the stacktrace.

 >  NX   Workspace creation failed, see above.

   Pass --verbose to see the stacktrace.

### Package Manager Version

_No response_

### Operating System

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

### Additional Information

_No response_
MBGuldhammer commented 10 months ago

Same when running npx create-nx-workspace@latest --allPrompts true

Here's the error log:

$ C:\Users\MYUSER\AppData\Local\Temp\tmp-16180-q0NSR9s1LxKN\node_modules\.bin\nx new --allPrompts --a --interactive --standaloneApi --routing --no-skipGit --no-g "--commit.message=Initial commit" --$0=..\..\AppData\Local\npm-cache\_npx\505743838affa773\node_modules\create-nx-workspace\bin\index.js --name=MYPROJECT--stack=none --preset=apps --no-nxCloud --packageManager=yarn --defaultBase=main --ci= --nxWorkspaceRoot=C:/Users/MYUSER/Documents/SRVScan
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

C:\Users\MYUSER\AppData\Local\Temp\tmp-16180-q0NSR9s1LxKN\node_modules\nx\bin\nx.js:137
    globalThis.GLOBAL_NX_VERSION ??= GLOBAL_NX_VERSION;
                                 ^^^

SyntaxError: Unexpected token '??='
    at wrapSafe (internal/modules/cjs/loader.js:1029:16)
    at Module._compile (internal/modules/cjs/loader.js:1078:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
    at Module.load (internal/modules/cjs/loader.js:979:32)
    at Function.Module._load (internal/modules/cjs/loader.js:819:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
    at internal/main/run_main_module.js:17:47
error Command failed with exit code 1.
aloksharma1 commented 10 months ago

i am getting the same issue with nx angular workspace setup, i was simply trying to create a test app with getting-started documentation. this happened with whenever i tried to use pnpm & yarn (only npm succeeded), my node version in v18.17.1.

here is my error log:

 NX   Creating your v17.1.1 workspace.

   To make sure the command works reliably in all environments, and that the preset is applied correctly,
   Nx will run "pnpm install" several times. Please wait.

✔ Installing dependencies with pnpm
✖ Creating your workspace in org

 >  NX   Failed to create a workspace.

   Exit code: 1
   Log file: C:\Users\Alok\AppData\Local\Temp\tmp-32240-jsNEdWVV5agw\error.log
Progress: resolved 1, reused 0, downloaded 0, added 0
Progress: resolved 3, reused 3, downloaded 0, added 0
Progress: resolved 4, reused 4, downloaded 0, added 0
Progress: resolved 37, reused 13, downloaded 0, added 0
Progress: resolved 147, reused 138, downloaded 0, added 0
Progress: resolved 156, reused 147, downloaded 0, added 0
Progress: resolved 157, reused 147, downloaded 0, added 0
Progress: resolved 200, reused 147, downloaded 0, added 0
Progress: resolved 207, reused 147, downloaded 0, added 0
Progress: resolved 208, reused 147, downloaded 0, added 0
Progress: resolved 284, reused 275, downloaded 0, added 0
Progress: resolved 375, reused 349, downloaded 0, added 0
Progress: resolved 468, reused 450, downloaded 0, added 0
Progress: resolved 591, reused 562, downloaded 0, added 0
Progress: resolved 715, reused 703, downloaded 0, added 0
Progress: resolved 846, reused 776, downloaded 0, added 0
Progress: resolved 862, reused 776, downloaded 0, added 0
Progress: resolved 863, reused 776, downloaded 0, added 0
Progress: resolved 863, reused 777, downloaded 0, added 0
Progress: resolved 892, reused 882, downloaded 0, added 0
Progress: resolved 894, reused 884, downloaded 0, added 0
Progress: resolved 895, reused 884, downloaded 0, added 0
Progress: resolved 1056, reused 1003, downloaded 0, added 0
Progress: resolved 1079, reused 1026, downloaded 0, added 0
Progress: resolved 1097, reused 1044, downloaded 0, added 0
Progress: resolved 1098, reused 1045, downloaded 0, added 0
Progress: resolved 1100, reused 1047, downloaded 0, added 0
Packages: +1132
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 1103, reused 1049, downloaded 0, added 0
Progress: resolved 1103, reused 1050, downloaded 0, added 0
Packages are hard linked from the content-addressable store to the virtual store.
  Content-addressable store is at: E:\.pnpm-store\v3
  Virtual store is at:             node_modules/.pnpm
Progress: resolved 1103, reused 1050, downloaded 0, added 29
Progress: resolved 1103, reused 1050, downloaded 0, added 49
Progress: resolved 1103, reused 1050, downloaded 0, added 56
Progress: resolved 1103, reused 1050, downloaded 0, added 72
Progress: resolved 1103, reused 1050, downloaded 0, added 73
Progress: resolved 1103, reused 1050, downloaded 0, added 127
Progress: resolved 1103, reused 1050, downloaded 0, added 131
Progress: resolved 1103, reused 1050, downloaded 0, added 132
Progress: resolved 1103, reused 1050, downloaded 0, added 147
Progress: resolved 1103, reused 1050, downloaded 0, added 243
Progress: resolved 1103, reused 1050, downloaded 0, added 247
Progress: resolved 1103, reused 1050, downloaded 0, added 248
Progress: resolved 1103, reused 1050, downloaded 0, added 274
Progress: resolved 1103, reused 1050, downloaded 0, added 384
Progress: resolved 1103, reused 1050, downloaded 0, added 385
Progress: resolved 1103, reused 1050, downloaded 0, added 564
Progress: resolved 1103, reused 1050, downloaded 0, added 569
Progress: resolved 1103, reused 1050, downloaded 0, added 570
Progress: resolved 1103, reused 1050, downloaded 0, added 719
Progress: resolved 1103, reused 1050, downloaded 0, added 743
Progress: resolved 1103, reused 1050, downloaded 0, added 744
Progress: resolved 1103, reused 1050, downloaded 0, added 828
Progress: resolved 1103, reused 1050, downloaded 0, added 906
Progress: resolved 1103, reused 1050, downloaded 0, added 1018
Progress: resolved 1103, reused 1050, downloaded 0, added 1019
Progress: resolved 1103, reused 1050, downloaded 0, added 1042
Progress: resolved 1103, reused 1050, downloaded 0, added 1046
Progress: resolved 1103, reused 1050, downloaded 0, added 1052
Progress: resolved 1103, reused 1050, downloaded 0, added 1054
Progress: resolved 1103, reused 1050, downloaded 0, added 1055
Progress: resolved 1103, reused 1050, downloaded 0, added 1062
Progress: resolved 1103, reused 1050, downloaded 0, added 1064
Progress: resolved 1103, reused 1050, downloaded 0, added 1065
Progress: resolved 1103, reused 1050, downloaded 0, added 1068
Progress: resolved 1103, reused 1050, downloaded 0, added 1069
Progress: resolved 1103, reused 1050, downloaded 0, added 1075
Progress: resolved 1103, reused 1050, downloaded 0, added 1076
Progress: resolved 1103, reused 1050, downloaded 0, added 1082
Progress: resolved 1103, reused 1050, downloaded 0, added 1083
Progress: resolved 1103, reused 1050, downloaded 0, added 1095
Progress: resolved 1103, reused 1050, downloaded 0, added 1099
Progress: resolved 1103, reused 1050, downloaded 0, added 1128
Progress: resolved 1103, reused 1050, downloaded 0, added 1129
Progress: resolved 1103, reused 1050, downloaded 0, added 1132, done
.../esbuild@0.18.20/node_modules/esbuild postinstall$ node install.js
.../esbuild@0.19.5/node_modules/esbuild postinstall$ node install.js
.../.pnpm/nx@17.1.1/node_modules/nx postinstall$ node ./bin/post-install
.../esbuild@0.19.5/node_modules/esbuild postinstall: Done
.../esbuild@0.18.20/node_modules/esbuild postinstall: Done
.../.pnpm/nx@17.1.1/node_modules/nx postinstall: Done

dependencies:
+ @nx/angular 17.1.1

devDependencies:
+ @angular-devkit/core 17.0.0
+ @nx/workspace 17.1.1
+ nx 17.1.1
+ typescript 5.2.2

Done in 2m 18.5s

>  NX  Generating @nx/workspace:preset

Fetching prettier...
Fetching @nx/playwright...
UPDATE nx.json
CREATE tsconfig.base.json
CREATE .prettierrc
CREATE .prettierignore
UPDATE .vscode/extensions.json
UPDATE package.json
CREATE jest.preset.js
CREATE jest.config.ts
UPDATE .gitignore
CREATE apps/shell/project.json
CREATE apps/shell/src/assets/.gitkeep
CREATE apps/shell/src/favicon.ico
CREATE apps/shell/src/index.html
CREATE apps/shell/src/styles.scss
CREATE apps/shell/tsconfig.app.json
CREATE apps/shell/tsconfig.editor.json
CREATE apps/shell/tsconfig.json
CREATE apps/shell/src/app/app.component.html
CREATE apps/shell/src/app/app.component.spec.ts
CREATE apps/shell/src/app/app.component.ts
CREATE apps/shell/src/app/app.component.scss
CREATE apps/shell/src/app/app.config.ts
CREATE apps/shell/src/app/app.routes.ts
CREATE apps/shell/src/app/nx-welcome.component.ts
CREATE apps/shell/src/main.ts
CREATE .eslintrc.json
CREATE .eslintignore
CREATE apps/shell/.eslintrc.json
CREATE apps/shell/jest.config.ts
CREATE apps/shell/src/test-setup.ts
CREATE apps/shell/tsconfig.spec.json
CREATE apps/shell-e2e/project.json
CREATE apps/shell-e2e/playwright.config.ts
CREATE apps/shell-e2e/src/example.spec.ts
CREATE apps/shell-e2e/.eslintrc.json
Progress: resolved 1, reused 0, downloaded 0, added 0
Progress: resolved 26, reused 24, downloaded 0, added 0
Progress: resolved 43, reused 43, downloaded 0, added 0
Progress: resolved 45, reused 45, downloaded 0, added 0
Progress: resolved 47, reused 47, downloaded 0, added 0
Progress: resolved 182, reused 181, downloaded 0, added 0
Progress: resolved 232, reused 222, downloaded 0, added 0
Progress: resolved 289, reused 267, downloaded 0, added 0
Progress: resolved 396, reused 330, downloaded 0, added 0
Progress: resolved 519, reused 398, downloaded 0, added 0
Progress: resolved 632, reused 437, downloaded 0, added 0
Progress: resolved 687, reused 511, downloaded 0, added 0
Progress: resolved 760, reused 706, downloaded 0, added 0
Progress: resolved 878, reused 834, downloaded 0, added 0
Progress: resolved 1012, reused 949, downloaded 0, added 0
Progress: resolved 1094, reused 1030, downloaded 0, added 0
Progress: resolved 1181, reused 1118, downloaded 0, added 0
Progress: resolved 1252, reused 1189, downloaded 0, added 0
Progress: resolved 1270, reused 1207, downloaded 0, added 0
Progress: resolved 1288, reused 1225, downloaded 0, added 0
Progress: resolved 1289, reused 1225, downloaded 0, added 0
Packages: +214 -32
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
Progress: resolved 1289, reused 1226, downloaded 0, added 0
Progress: resolved 1289, reused 1226, downloaded 0, added 17
Progress: resolved 1289, reused 1226, downloaded 0, added 23
Progress: resolved 1289, reused 1226, downloaded 0, added 35
Progress: resolved 1289, reused 1226, downloaded 0, added 43
Progress: resolved 1289, reused 1226, downloaded 0, added 53
Progress: resolved 1289, reused 1226, downloaded 0, added 54
Progress: resolved 1289, reused 1226, downloaded 0, added 55
Progress: resolved 1289, reused 1226, downloaded 0, added 62
Progress: resolved 1289, reused 1226, downloaded 0, added 63
Progress: resolved 1289, reused 1226, downloaded 0, added 199
Progress: resolved 1289, reused 1226, downloaded 0, added 205
Progress: resolved 1289, reused 1226, downloaded 0, added 209
Progress: resolved 1289, reused 1226, downloaded 0, added 210
Progress: resolved 1289, reused 1226, downloaded 0, added 211
Progress: resolved 1289, reused 1226, downloaded 0, added 214, done
.../node_modules/nx postinstall$ node ./bin/post-install
.../node_modules/nx postinstall: Done

dependencies:
+ @angular/animations 17.0.2
+ @angular/common 17.0.2
+ @angular/compiler 17.0.2
+ @angular/core 17.0.2
+ @angular/forms 17.0.2
+ @angular/platform-browser 17.0.2
+ @angular/platform-browser-dynamic 17.0.2
+ @angular/router 17.0.2
+ rxjs 7.8.1
+ tslib 2.6.2
+ zone.js 0.14.2

devDependencies:
+ @angular-devkit/build-angular 17.0.0
+ @angular-devkit/schematics 17.0.0
+ @angular-eslint/eslint-plugin 17.0.1
+ @angular-eslint/eslint-plugin-template 17.0.1
+ @angular-eslint/template-parser 17.0.1
+ @angular/cli 17.0.0
+ @angular/compiler-cli 17.0.2
+ @angular/language-service 17.0.2
+ @nx/devkit 17.1.1
+ @nx/eslint 17.1.1
+ @nx/eslint-plugin 17.1.1
+ @nx/jest 17.1.1
+ @nx/js 17.1.1
+ @nx/playwright 17.1.1
+ @playwright/test 1.39.0
+ @schematics/angular 17.0.0
+ @swc-node/register 1.6.8
+ @swc/core 1.3.96
+ @types/jest 29.5.8
+ @types/node 16.11.7 (20.9.0 is available)
+ @typescript-eslint/eslint-plugin 6.10.0
+ @typescript-eslint/parser 6.10.0
+ eslint 8.46.0 (8.53.0 is available)
+ eslint-config-prettier 9.0.0
+ eslint-plugin-playwright 0.15.3 (0.18.0 is available)
+ jest 29.7.0
+ jest-environment-jsdom 29.7.0
+ jest-preset-angular 13.1.4
+ jsonc-eslint-parser 2.4.0
+ prettier 2.8.8 (3.0.3 is available)
+ ts-jest 29.1.1
+ ts-node 10.9.1

Done in 56.8s

>  NX  Generating @nx/workspace:preset

 >  NX   Cannot create a new project shell at apps/shell. It already exists.

   Pass --verbose to see the stacktrace.

 >  NX   Workspace creation failed, see above.

Error: Workspace creation failed, see above.
    at ChildProcess.<anonymous> (C:\Users\Alok\AppData\Local\Temp\tmp-43728-RTv9gWiHItzm\node_modules\.pnpm\@nx+workspace@17.1.1\node_modules\@nx\workspace\src\generators\new\generate-preset.js:38:24)
    at ChildProcess.emit (node:events:514:28)
    at maybeClose (node:internal/child_process:1091:16)
    at ChildProcess._handle.onexit (node:internal/child_process:302:5)
leosvelperez commented 10 months ago

Hey all! Thanks for reporting these!

There are multiple issues in this thread, so it's harder to keep it focused. If anyone else is arriving here, please create a different issue if your error or failure logs are different than the one reported here. It will make things easier to track and address.


@soumyanildas the name you're providing to the workspace is failing a validation over the selector that's going to be used for the component. You can see that explained in the failure logs you got and shared above:

>  NX   The "--prefix" option was not provided, therefore attempted to use the "npmScope" defined in "nx.json" to set the application's selector prefix, but it is invalid.

   There are two options that can be followed to resolve this issue:
     - Pass a valid "--prefix" option.
     - Update the "npmScope" in "nx.json" (Note: this can be an involved process, as other libraries and applications may need to be updated to match the new scope).

   If you encountered this error when creating a new Nx Workspace, the workspace name or "npmScope" is invalid to use as the selector prefix for the application being generated.

   Valid selector prefixes must start with a letter, and must contain only alphanumeric characters or dashes.

After a dash (-), you need to use at least a letter and then it can be followed by numbers. Component selectors need to be valid HTML elements and the validation that's failing is the one used by Angular to validate those selectors. When creating a workspace, the name you provide is used as the prefix for component selectors. This is a bit of an unfortunate limitation at the moment and that's why you get the error message above. Please use a different name to create the workspace. We'll revisit this limitation at a later point to see if we can remove it.


@DireState88 please create a separate issue with the reproduction steps and the error logs you posted here. Make sure to also provide the nx report output, or if you can't because you don't have an Nx workspace (given it's failing to be created), please provide at least:


@aloksharma1 please create a separate issue with the reproduction steps and the error logs you posted here. Without the reproduction steps, it is hard to tell what exactly you ran and the possible cause of your issue. In the failure logs you shared, it'd seem you're trying to create something that already exists, but given it seems you're creating a new workspace, that shouldn't normally happen. We'll need the reproduction steps to be able to troubleshoot that.

soumyanildas commented 10 months ago

@leosvelperez Thank you so much. Works now!

leosvelperez commented 10 months ago

I'm going to close this, given the original issue was addressed. For the other issues described in this thread, please create separate issues with the reproduction steps and any other details that would help troubleshoot them.

aloksharma1 commented 10 months ago

Hey all! Thanks for reporting these!

There are multiple issues in this thread, so it's harder to keep it focused. If anyone else is arriving here, please create a different issue if your error or failure logs are different than the one reported here. It will make things easier to track and address.

@soumyanildas the name you're providing to the workspace is failing a validation over the selector that's going to be used for the component. You can see that explained in the failure logs you got and shared above:

>  NX   The "--prefix" option was not provided, therefore attempted to use the "npmScope" defined in "nx.json" to set the application's selector prefix, but it is invalid.

   There are two options that can be followed to resolve this issue:
     - Pass a valid "--prefix" option.
     - Update the "npmScope" in "nx.json" (Note: this can be an involved process, as other libraries and applications may need to be updated to match the new scope).

   If you encountered this error when creating a new Nx Workspace, the workspace name or "npmScope" is invalid to use as the selector prefix for the application being generated.

   Valid selector prefixes must start with a letter, and must contain only alphanumeric characters or dashes.

After a dash (-), you need to use at least a letter and then it can be followed by numbers. Component selectors need to be valid HTML elements and the validation that's failing is the one used by Angular to validate those selectors. When creating a workspace, the name you provide is used as the prefix for component selectors. This is a bit of an unfortunate limitation at the moment and that's why you get the error message above. Please use a different name to create the workspace. We'll revisit this limitation at a later point to see if we can remove it.

@DireState88 please create a separate issue with the reproduction steps and the error logs you posted here. Make sure to also provide the nx report output, or if you can't because you don't have an Nx workspace (given it's failing to be created), please provide at least:

  • Node version
  • OS
  • Package manager and its version

@aloksharma1 please create a separate issue with the reproduction steps and the error logs you posted here. Without the reproduction steps, it is hard to tell what exactly you ran and the possible cause of your issue. In the failure logs you shared, it'd seem you're trying to create something that already exists, but given it seems you're creating a new workspace, that shouldn't normally happen. We'll need the reproduction steps to be able to troubleshoot that.

i have made a separate issue as per your request, please look through it.

dev202312 commented 9 months ago

Can you please share where the GLOBAL_NX_VERSION issue is being discussed? Am facing a similar issue.

github-actions[bot] commented 8 months ago

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.