nrwl / nx

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

Builing angular app compiles also nest library #10904

Closed wmedia closed 2 years ago

wmedia commented 2 years ago

Current Behavior

I have a monorepo angular and nestjs like:

apps/ myapp (angular app) api (nestjs app) libs/ core (nest library) auth (angular library)

When compiling myapp yarn nx build myapp

Ccompiles lib/core also, but at myapp doesn't have any dependency or import reference to core library ans gets errors.

While compiling just the api app which it has dependency to the lib/core doesn't get any errors, and compiles well.

There is no sense to try to compile another app dependencies on the workspace. Maybe I am wrong?

Expected Behavior

Compiling angular app should not compile lib/core because the app doesn't reference to it.

Steps to Reproduce

yarn nx build angular or yarn nx serve angular

Failure Logs

./node_modules/@nestjs/core/nest-application.js:40:86-129 - Error: Module not found: Error: Can't resolve '@nestjs/websockets/socket-module' in '/home/wmediape/angular/myapp/node_modules/@nestjs/core'

./node_modules/@nestjs/core/nest-application.js:43:96-149 - Error: Module not found: Error: Can't resolve '@nestjs/microservices/microservices-module' in '/home/wmediape/angular/myapp/node_modules/@nestjs/core'

./node_modules/@nestjs/core/nest-application.js:202:91-123 - Error: Module not found: Error: Can't resolve '@nestjs/microservices' in '/home/wmediape/angular/myapp/node_modules/@nestjs/core'

./node_modules/@nestjs/core/nest-factory.js:88:93-125 - Error: Module not found: Error: Can't resolve '@nestjs/microservices' in '/home/wmediape/angular/myapp/node_modules/@nestjs/core'

./node_modules/@nestjs/core/router/sse-stream.js:10:17-34 - Error: Module not found: Error: Can't resolve 'stream' in '/home/wmediape/angular/myapp/node_modules/@nestjs/core/router'

./node_modules/cls-hooked/context-legacy.js:3:13-28 - Error: Module not found: Error: Can't resolve 'util' in '/home/wmediape/angular/myapp/node_modules/cls-hooked'

./node_modules/cls-hooked/context.js:10:20-42 - Error: Module not found: Error: Can't resolve 'async_hooks' in '/home/wmediape/angular/myapp/node_modules/cls-hooked'

./node_modules/content-disposition/index.js:19:15-39 - Error: Module not found: Error: Can't resolve 'path' in '/home/wmediape/angular/myapp/node_modules/content-disposition'

./node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html:1:0 - Error: Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

<!doctype html> | |

./node_modules/node-gyp/lib/Find-VisualStudio.cs:9:6 - Error: Module parse failed: Unexpected token (9:6)

Environment

OS: Linux Centos 8

{ "name": "myapp", "version": "0.0.0", "license": "MIT", "scripts": { "start": "nx serve", "build": "nx build", "test": "nx test", "postinstall": "ngcc --properties es2020 browser module main" }, "private": true, "dependencies": { "@angular/animations": "~14.0.0", "@angular/common": "~14.0.0", "@angular/compiler": "~14.0.0", "@angular/core": "~14.0.0", "@angular/forms": "~14.0.0", "@angular/platform-browser": "~14.0.0", "@angular/platform-browser-dynamic": "~14.0.0", "@angular/router": "~14.0.0", "@datorama/akita": "^7.1.1", "@nebular/auth": "^9.0.3", "@nebular/security": "^9.0.3", "@nestjs/common": "^8.0.0", "@nestjs/core": "^8.0.0", "@nestjs/mapped-types": "^1.0.1", "@nestjs/passport": "^8.2.2", "@nestjs/platform-express": "^8.0.0", "@nestjs/typeorm": "^8.1.4", "@ng-bootstrap/ng-bootstrap": "^12.1.2", "@ngneat/until-destroy": "^9.2.1", "@popperjs/core": "^2.11.5", "bcrypt": "^5.0.1", "class-transformer": "^0.5.1", "class-validator": "^0.13.2", "cls-hooked": "^4.2.2", "express-session": "^1.17.3", "jsonwebtoken": "^8.5.1", "metismenujs": "^1.3.1", "moment": "^2.29.3", "ng2-completer": "^9.0.1", "ng2-smart-table": "^1.7.2", "ngx-cookie-service": "^14.0.0", "ngx-permissions": "^13.0.1", "ngx-toastr": "^15.0.0", "passport": "^0.6.0", "passport-jwt": "^4.0.0", "passport-local": "^1.0.0", "pg": "^8.7.3", "reflect-metadata": "^0.1.13", "rxjs": "^7.0.0", "simplebar-angular": "^2.4.0", "tslib": "^2.3.0", "typeorm": "^0.3.6", "zone.js": "~0.11.4" }, "devDependencies": { "@angular-devkit/build-angular": "~14.0.0", "@angular-eslint/eslint-plugin": "~13.2.1", "@angular-eslint/eslint-plugin-template": "~13.2.1", "@angular-eslint/template-parser": "~13.2.1", "@angular/cli": "~14.0.0", "@angular/compiler-cli": "~14.0.0", "@angular/language-service": "~14.0.0", "@nestjs/schematics": "^8.0.0", "@nestjs/testing": "^8.0.0", "@nrwl/angular": "^14.3.6", "@nrwl/cli": "14.3.6", "@nrwl/cypress": "14.3.6", "@nrwl/eslint-plugin-nx": "14.3.6", "@nrwl/jest": "14.3.6", "@nrwl/linter": "14.3.6", "@nrwl/nest": "^14.3.6", "@nrwl/node": "14.3.6", "@nrwl/workspace": "14.3.6", "@types/express-session": "^1.17.4", "@types/jest": "27.4.1", "@types/node": "16.11.7", "@types/passport-local": "^1.0.34", "@typescript-eslint/eslint-plugin": "~5.24.0", "@typescript-eslint/parser": "~5.24.0", "cypress": "^9.1.0", "eslint": "~8.15.0", "eslint-config-prettier": "8.1.0", "eslint-plugin-cypress": "^2.10.3", "jest": "27.5.1", "jest-preset-angular": "~11.1.2", "ng-packagr": "~14.0.0", "nx": "14.3.6", "postcss": "^8.4.5", "postcss-import": "~14.1.0", "postcss-preset-env": "~7.5.0", "postcss-url": "~10.1.3", "prettier": "^2.6.2", "ts-jest": "27.1.4", "ts-node": "~10.8.0", "typescript": "~4.7.2" } }

wmedia commented 2 years ago

Sorry a mistake coding

HarroGutz commented 2 years ago

Hello wedia, what was your coding error? This behavior is happening to me too.

Dariant31 commented 2 years ago

Hallo @wmedia, can you please share what the mistake is? because i'm also getting the same error, and have no idea what i did wrong

wmedia commented 1 year ago

@Dariant31 I was trying many things, but for last I created a new project with the lasted angular version, and copied my code to the new project and worked. Trying to update was unsuccessful.

drakedeatonuk commented 1 year ago

It's worth checking your nx.json config. I had a similar issue due to this code in my nx.json:

...
"targetDependencies": {
    "build": [
      {
        "target": "build",
        "projects": "dependencies"
      }
    ]
  },
...

Removing the target dependencies altogether solved the issue for me.

github-actions[bot] commented 1 year 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.