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

feat/docs: update setup nx #951

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

honguyenhaituan
Copy link

Update docs setup nestia with nx

@samchon
Copy link
Owner

samchon commented Jul 22, 2024

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 samchon self-requested a review July 22, 2024 07:34
@samchon samchon added help wanted Extra attention is needed question Further information is requested labels Jul 22, 2024
After that you have to turn off option "transpileOnly": false (default nx use option "transpileOnly": true) like blow:

```json filename="webpack.config.js" showLineNumbers copy
const { composePlugins, withNx } = require('@nx/webpack');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't necessay in my case

After install `nestia` like above, you have to modify `project.json` on each app you use typia like below.

```javascript filename="project.json" showLineNumbers copy
"targets": {
Copy link

@BaptisteMahe BaptisteMahe Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary in your project.json inside the nestia app. And should not be removed from the documentation.

After install `nestia` like above, you have to configure tsconfig.base.json (or ts.config.json on app you use nestia) like blow.

```json filename="tsconfig.json" showLineNumbers copy
{
Copy link

@BaptisteMahe BaptisteMahe Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this should be added to the documentation.

But I think it's better to recommend not having this inside the global tsconfig.base.json but inside each tsconfig.app.json for each nestia app inside the NX monorepo.

In some cases those plugins can interfere with Angular apps and prevent them from building if this is sets inside the tsconfig.base.json

@BaptisteMahe
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants