nestia icon indicating copy to clipboard operation
nestia copied to clipboard

feat/docs: update setup nx

Open honguyenhaituan opened this issue 1 year ago • 2 comments

Update docs setup nestia with nx

honguyenhaituan avatar Jul 10 '24 15:07 honguyenhaituan

I cannot understand the reason why not to using npx nestia setup command.

Any special reason not to using the npx nestia setup command?

Also, you're adding another TypeScript project configuration file instead of tsconfig.json. Can you explain me why?

samchon avatar Jul 22 '24 07:07 samchon

@samchon I can reply with my own experience setting up nestia inside an NX monorepo:

Any special reason not to using the npx nestia setup command?

The npx nestia setup command tries to install the latest version of typescript which is already installed and often the current version of Angular prevent you from updating to the latest version of typescript which makes the setup command unusable in my case and I had to default to the manual installation.

This error is not specific to NX but more to a monorepo with Angular installed (which is pretty strict on which ts version is installed). But nowadays most monorepos with Angular are NX monorepos.

Maybe the issue comes from the fact that npx nestia setup tryies to install the latest version of typescript even if one is already installed. And maybe this should be fixed instead of the docs.

Here is the tail of the error I was facing trying to run npx nestia setup:

$ npm i -D typescript@^5.6.2
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/typescript
npm WARN   peer typescript@">=5.4 <5.6" from @angular-devkit/[email protected]
npm WARN   node_modules/@angular-devkit/build-angular
npm WARN     peer @angular-devkit/build-angular@">= 16.0.0 < 19.0.0" from @nx/[email protected]
npm WARN     node_modules/@nx/angular
npm WARN     2 more (jest-preset-angular, the root project)
npm WARN   37 more (@angular/build, @angular-eslint/builder, ...)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer typescript@">=5.4 <5.6" from @angular-devkit/[email protected]
npm WARN node_modules/@angular-devkit/build-angular
npm WARN   peer @angular-devkit/build-angular@">= 16.0.0 < 19.0.0" from @nx/[email protected]
npm WARN   node_modules/@nx/angular
npm WARN   2 more (jest-preset-angular, the root project)
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/typescript
npm WARN   peer typescript@">=5.4 <5.6" from @angular-devkit/[email protected]
npm WARN   node_modules/@angular-devkit/build-angular
npm WARN     peer @angular-devkit/build-angular@">= 16.0.0 < 19.0.0" from @nx/[email protected]
npm WARN     node_modules/@nx/angular
npm WARN     2 more (jest-preset-angular, the root project)
npm WARN   37 more (@angular/build, @angular-eslint/builder, ...)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer typescript@">=5.4 <5.6" from @angular-devkit/[email protected]
npm WARN node_modules/@angular-devkit/build-angular
npm WARN   peer @angular-devkit/build-angular@">= 16.0.0 < 19.0.0" from @nx/[email protected]
npm WARN   node_modules/@nx/angular
npm WARN   2 more (jest-preset-angular, the root project)
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/typescript
npm WARN   peer typescript@">=5.4 <5.6" from @angular-devkit/[email protected]
npm WARN   node_modules/@angular-devkit/build-angular
npm WARN     peer @angular-devkit/build-angular@">= 16.0.0 < 19.0.0" from @nx/[email protected]
npm WARN     node_modules/@nx/angular
npm WARN     2 more (jest-preset-angular, the root project)
npm WARN   37 more (@angular/build, @angular-eslint/builder, ...)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer typescript@">=5.4 <5.6" from @angular-devkit/[email protected]
npm WARN node_modules/@angular-devkit/build-angular
npm WARN   peer @angular-devkit/build-angular@">= 16.0.0 < 19.0.0" from @nx/[email protected]
npm WARN   node_modules/@nx/angular
npm WARN   2 more (jest-preset-angular, the root project)
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/typescript
npm WARN   peer typescript@">=5.4 <5.6" from @angular-devkit/[email protected]
npm WARN   node_modules/@angular-devkit/build-angular
npm WARN     peer @angular-devkit/build-angular@">= 16.0.0 < 19.0.0" from @nx/[email protected]
npm WARN     node_modules/@nx/angular
npm WARN     2 more (jest-preset-angular, the root project)
npm WARN   37 more (@angular/build, @angular-eslint/builder, ...)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer typescript@">=5.4 <5.6" from @angular/[email protected]
npm WARN node_modules/@angular/compiler-cli
npm WARN   peer @angular/compiler-cli@"^18.0.0" from @angular-devkit/[email protected]
npm WARN   node_modules/@angular-devkit/build-angular
npm WARN   5 more (@angular/build, @angular/localize, @ngtools/webpack, ...)
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/typescript
npm WARN   peer typescript@">=5.4 <5.6" from @angular-devkit/[email protected]
npm WARN   node_modules/@angular-devkit/build-angular
npm WARN     peer @angular-devkit/build-angular@">= 16.0.0 < 19.0.0" from @nx/[email protected]
npm WARN     node_modules/@nx/angular
npm WARN     2 more (jest-preset-angular, the root project)
npm WARN   37 more (@angular/build, @angular-eslint/builder, ...)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer typescript@">=5.4 <5.6" from @angular/[email protected]
npm WARN node_modules/@angular/compiler-cli
npm WARN   peer @angular/compiler-cli@"^18.0.0" from @angular-devkit/[email protected]
npm WARN   node_modules/@angular-devkit/build-angular
npm WARN   5 more (@angular/build, @angular/localize, @ngtools/webpack, ...)
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/typescript
npm WARN   peer typescript@">=5.4 <5.6" from @angular-devkit/[email protected]
npm WARN   node_modules/@angular-devkit/build-angular
npm WARN     peer @angular-devkit/build-angular@">= 16.0.0 < 19.0.0" from @nx/[email protected]
npm WARN     node_modules/@nx/angular
npm WARN     2 more (jest-preset-angular, the root project)
npm WARN   37 more (@angular/build, @angular-eslint/builder, ...)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer typescript@">=5.4 <5.6" from @angular/[email protected]
npm WARN node_modules/@angular/compiler-cli
npm WARN   peer @angular/compiler-cli@"^18.0.0" from @angular-devkit/[email protected]
npm WARN   node_modules/@angular-devkit/build-angular
npm WARN   5 more (@angular/build, @angular/localize, @ngtools/webpack, ...)
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/typescript
npm WARN   peer typescript@">=5.4 <5.6" from @angular-devkit/[email protected]
npm WARN   node_modules/@angular-devkit/build-angular
npm WARN     peer @angular-devkit/build-angular@">= 16.0.0 < 19.0.0" from @nx/[email protected]
npm WARN     node_modules/@nx/angular
npm WARN     2 more (jest-preset-angular, the root project)
npm WARN   37 more (@angular/build, @angular-eslint/builder, ...)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer typescript@">=5.4 <5.6" from @angular/[email protected]
npm WARN node_modules/@angular/compiler-cli
npm WARN   peer @angular/compiler-cli@"^18.0.0" from @angular-devkit/[email protected]
npm WARN   node_modules/@angular-devkit/build-angular
npm WARN   5 more (@angular/build, @angular/localize, @ngtools/webpack, ...)
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]
npm WARN node_modules/typescript
npm WARN   peer typescript@">=5.4 <5.6" from @angular-devkit/[email protected]
npm WARN   node_modules/@angular-devkit/build-angular
npm WARN     peer @angular-devkit/build-angular@">= 16.0.0 < 19.0.0" from @nx/[email protected]
npm WARN     node_modules/@nx/angular
npm WARN     2 more (jest-preset-angular, the root project)
npm WARN   37 more (@angular/build, @angular-eslint/builder, ...)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer typescript@">=5.4 <5.6" from @angular/[email protected]
npm WARN node_modules/@angular/compiler-cli
npm WARN   peer @angular/compiler-cli@"^18.0.0" from @angular-devkit/[email protected]
npm WARN   node_modules/@angular-devkit/build-angular
npm WARN   5 more (@angular/build, @angular/localize, @ngtools/webpack, ...)
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/typescript
npm ERR!   dev typescript@"^5.6.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer typescript@">=5.4 <5.6" from @angular/[email protected]
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   dev @angular/compiler-cli@"18.2.1" from the root project
npm ERR!   peer @angular/compiler-cli@"^18.0.0" from @angular-devkit/[email protected]
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"18.2.1" from the root project
npm ERR!     1 more (@nx/angular)
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! 
npm ERR! For a full report see:
npm ERR! /Users/baptistemahe/.npm/_logs/2024-10-29T10_13_07_293Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in: /Users/baptistemahe/.npm/_logs/2024-10-29T10_13_07_293Z-debug-0.log
Command failed: npm i -D typescript@^5.6.2

Also, you're adding another TypeScript project configuration file instead of tsconfig.json. Can you explain me why?

NX monorepos works with multiples tsconfig.json, here is a small breakdown of them:

  • ./tsconfig.base.ts -> The root tsconfig for configs shared across all apps and libs of the monorepo.
  • ./apps/app-1/tsconfig.json -> tsconfig specific to the application named "app-1" it extends ./tsconfig.base.ts.
  • ./apps/app-1/tsconfig.app.json -> tsconifg for running "app-1", it extends ./apps/app-1/tsconfig.json.
  • ./apps/app-1/tsconfig.spec.json -> tsconifg for running tests on "app-1", it extends ./apps/app-1/tsconfig.json.

Then there is the same tsconfig(.app | .spec).json inside each lib (./libs/lib-1).

Regarding the Nestia setup inside my NX monorepo I have had some issues adding the transform plugins directly inside the ./tsconfig.base.ts because of it interfering with my Angular apps (maybe I can give you the error log if you want to investigate). So I just added the plugins inside the ./apps/app-1/tsconfig.json of the application using Nestia and it worked fine.

BaptisteMahe avatar Oct 29 '24 10:10 BaptisteMahe