Angular-cli: [6.0.0-rc.4] `ng test --prod` fails

Created on 13 Apr 2018  路  4Comments  路  Source: angular/angular-cli

Versions

Angular CLI: 6.0.0-rc.4
Node: 8.11.1
OS: linux x64
Angular: 6.0.0-rc.4
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.5.6
@angular-devkit/build-angular     0.5.6
@angular-devkit/build-optimizer   0.5.6
@angular-devkit/core              0.5.6
@angular-devkit/schematics        0.5.6
@ngtools/json-schema              1.1.0
@ngtools/webpack                  6.0.0-rc.4
@schematics/angular               0.5.6
@schematics/update                0.5.6
rxjs                              6.0.0-turbo-rc.4
typescript                        2.7.2
webpack                           4.5.0

Repro steps

$ ng new testproject
$ cd testproject
$ ng test --prod

Observed behavior

Configuration 'production' could not be found in project 'testproject'.
Error: Configuration 'production' could not be found in project 'testproject'.
    at Architect.getBuilderConfiguration (/tmp/bla/testproject/node_modules/@angular-devkit/architect/src/architect.js:102:23)
    at runSingleTarget (/tmp/bla/testproject/node_modules/@angular/cli/models/architect-command.js:136:89)
    at MergeMapSubscriber.rxjs_2.from.pipe.operators_1.concatMap.project (/tmp/bla/testproject/node_modules/@angular/cli/models/architect-command.js:141:131)
    at MergeMapSubscriber._tryNext (/tmp/bla/testproject/node_modules/rxjs/internal/operators/mergeMap.js:122:27)
    at MergeMapSubscriber._next (/tmp/bla/testproject/node_modules/rxjs/internal/operators/mergeMap.js:112:18)
    at MergeMapSubscriber.Subscriber.next (/tmp/bla/testproject/node_modules/rxjs/internal/Subscriber.js:103:18)
    at Observable._subscribe (/tmp/bla/testproject/node_modules/rxjs/internal/util/subscribeToArray.js:9:20)
    at Observable._trySubscribe (/tmp/bla/testproject/node_modules/rxjs/internal/Observable.js:177:25)
    at Observable.subscribe (/tmp/bla/testproject/node_modules/rxjs/internal/Observable.js:162:93)
    at MergeMapOperator.call (/tmp/bla/testproject/node_modules/rxjs/internal/operators/mergeMap.js:87:23)

Desired behavior

Builds app and runs test, like it does without --prod

Most helpful comment

You need to add production section to test in angular.json

          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }
          }

All 4 comments

You need to add production section to test in angular.json

          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }
          }

The configuration is included in the generated angular.json:

{
  "projects": {
    "testproject": {
      "architect": {
        "build": {
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
            }
          }
        },

(removed irrelevant keys)

Build configuration and test configuration are different. You need to add it as @rokerkony mentioned.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings