nrwl / nx

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

Target 'server' could not be found in project 'frontend' #713

Closed github-mayur closed 6 years ago

github-mayur commented 6 years ago

Hello, I am working on Angular 6 and trying to build application Server Side Rendering from several days.

I am continuously facing an error as below

"C:\JetBrains\PhpStorm 2018.2\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" run build:ssr --scripts-prepend-node-path=auto

> frontend@0.0.0 build:ssr C:\Users\mchampaneria\phpstormprojects\angular_win\frontend
> npm run build:client-and-server-bundles && npm run webpack:server

> frontend@0.0.0 build:client-and-server-bundles C:\Users\mchampaneria\phpstormprojects\angular_win\frontend
> ng run frontend:server

Target 'server' could not be found in project 'frontend'.
Error: Target 'server' could not be found in project 'frontend'.
    at Architect._getProjectTarget (C:\Users\mchampaneria\phpstormprojects\angular_win\frontend\node_modules\@angular-devkit\architect\src\architect.js:90:19)
    at Architect.getBuilderConfiguration (C:\Users\mchampaneria\phpstormprojects\angular_win\frontend\node_modules\@angular-devkit\architect\src\architect.js:97:29)
    at MergeMapSubscriber._loadWorkspaceAndArchitect.pipe.operators_1.concatMap [as project] (C:\Users\mchampaneria\phpstormprojects\angular_win\frontend\node_modules\@angular\cli\models\architect-command.js:72:55)
    at MergeMapSubscriber._tryNext (C:\Users\mchampaneria\phpstormprojects\angular_win\frontend\node_modules\rxjs\internal\operators\mergeMap.js:65:27)
    at MergeMapSubscriber._next (C:\Users\mchampaneria\phpstormprojects\angular_win\frontend\node_modules\rxjs\internal\operators\mergeMap.js:55:18)
    at MergeMapSubscriber.Subscriber.next (C:\Users\mchampaneria\phpstormprojects\angular_win\frontend\node_modules\rxjs\internal\Subscriber.js:64:18)
    at TapSubscriber._next (C:\Users\mchampaneria\phpstormprojects\angular_win\frontend\node_modules\rxjs\internal\operators\tap.js:62:26)
    at TapSubscriber.Subscriber.next (C:\Users\mchampaneria\phpstormprojects\angular_win\frontend\node_modules\rxjs\internal\Subscriber.js:64:18)
    at MergeMapSubscriber.notifyNext (C:\Users\mchampaneria\phpstormprojects\angular_win\frontend\node_modules\rxjs\internal\operators\mergeMap.js:84:26)
    at InnerSubscriber._next (C:\Users\mchampaneria\phpstormprojects\angular_win\frontend\node_modules\rxjs\internal\InnerSubscriber.js:25:21)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend@0.0.0 build:client-and-server-bundles: `ng run frontend:server`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the frontend@0.0.0 build:client-and-server-bundles script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\mchampaneria\AppData\Roaming\npm-cache\_logs\2018-08-17T09_15_10_808Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend@0.0.0 build:ssr: `npm run build:client-and-server-bundles && npm run webpack:server`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the frontend@0.0.0 build:ssr script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\mchampaneria\AppData\Roaming\npm-cache\_logs\2018-08-17T09_15_10_839Z-debug.log

Process finished with exit code 1

Since, my project name is 'frontend' and I am executing commands like below, after following full document describe on Angular Universal url

"build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server",
"serve:ssr": "node dist/server",
"build:client-and-server-bundles-old": "ng build --prod --extract-css && ng run frontend:server",
"webpack:server": "webpack --config webpack.server.config.js --progress --colors"

I was able to do this and successfully run server side rendering on Angular 5. But it is not working on Angular 6 and I have followed the changes done in Angular 6 too.

Is that any issue in Angular 6?

FrozenPandaz commented 6 years ago

Can you please post your angular.json?

github-mayur commented 6 years ago

This issue is solved. Thanks

TousifMir commented 5 years ago

@github-mayur What was the fix for this? Even I am getting struggling with this issue. Thanks.

A002465056 commented 4 years ago

I am getting the same error Project 'angular-universal-course:server' does not support the 'build' target my angular.json code is

{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "projects", "projects": { "angular-universal-course": { "root": "", "sourceRoot": "src", "projectType": "application", "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "dist", "index": "src/index.html", "main": "src/main.ts", "tsConfig": "src/tsconfig.app.json", "polyfills": "src/polyfills.ts", "assets": [ "src/assets", "src/favicon.ico" ], "styles": [ "src/styles.scss" ], "scripts": [] }, "configurations": { "production": { "optimization": true, "outputHashing": "all", "sourceMap": false, "extractCss": true, "namedChunks": false, "aot": true, "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true, "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ] } } }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { "browserTarget": "angular-universal-course:build" }, "configurations": { "production": { "browserTarget": "angular-universal-course:build:production" } } }, "extract-i18n": { "builder": "@angular-devkit/build-angular:extract-i18n", "options": { "browserTarget": "angular-universal-course:build" } }, "test": { "builder": "@angular-devkit/build-angular:karma", "options": { "main": "src/test.ts", "karmaConfig": "./karma.conf.js", "polyfills": "src/polyfills.ts", "tsConfig": "src/tsconfig.spec.json", "scripts": [], "styles": [ "src/styles.scss" ], "assets": [ "src/assets", "src/favicon.ico" ] } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": [ "src/tsconfig.app.json", "src/tsconfig.spec.json" ], "exclude": [ "/node_modules/" ] } }, "server": { "builder": "@angular-devkit/build-angular:server", "options": { "outputPath": "dist/angular-universal-course-server", "main": "src/main.server.ts", "tsConfig": "src/tsconfig.server.json" }, "configurations": { "production": { "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ], "sourceMap": false, "optimization": { "scripts": false, "styles": true } } } } } }, "angular-universal-course-e2e": { "root": "", "sourceRoot": "", "projectType": "application", "architect": { "e2e": { "builder": "@angular-devkit/build-angular:protractor", "options": { "protractorConfig": "./protractor.conf.js", "devServerTarget": "angular-universal-course:serve" } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": [ "e2e/tsconfig.e2e.json" ], "exclude": [ "/node_modules/" ] } } } } }, "defaultProject": "angular-universal-course", "schematics": { "@schematics/angular:component": { "prefix": "", "styleext": "scss" }, "@schematics/angular:directive": { "prefix": "" } } } please suggest me where I am doing wrong....Thanks..

kuldeeps1ngh commented 3 years ago

@github-mayur what is the solution of this error, I am also facing same issue. it will be great help if you can elaborate little about your solution . Thanks

tayambamwanza commented 3 years ago

@github-mayur how did you fix it?

tayambamwanza commented 3 years ago

@kuldeeps1ngh, @FrozenPandaz , @vishwapratap , @github-mayur , @TousifMir

Apparently when you run ng add for universal in nx it might not have added the appropriate targets in "architect" of your angular.json

I created a normal universal project and then copied the missing targets from the new projects angular.json to my current project and editing the path values to match the app in question.

Image of the old projects "architect" section for the app in question.

Screenshot from 2021-03-21 15-52-27

Image of the new projects "architect" section for the app in question

Screenshot from 2021-03-21 15-52-59

I had to add "apps" to the path for npm run serve:ssr command in package.json too i.e. "dist/apps/frontend-project".

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.