Configuration 'production' could not be found in project 'my-lib'

Beginning with version 6.1, Angular always does a production build of our library, i.e. in new versions of Angular we don't need the --prod flag anymore when building it, libraries are always built in AOT mode. To ensure, you can take a look at these issues in Angular-CLI repository:

https://github.com/angular/angular-cli/issues/12290

https://github.com/angular/angular-cli/issues/12226

And this article ("Building the Library" section):

https://blog.angularindepth.com/creating-a-library-in-angular-6-87799552e7e5

If you are still using version 6.0.x (or lower) you will want to use the --prod flag when building your library.

You still have an option to pass a configuration as a parameter if needed: ng build --configuration=configuration (see docs). If necessary, you can specify build rules in angular.json, for example, for production build:

"configurations": {
    "production": {
        // Options here
    }
}

And the command should be ng build --configuration=production.


In Angular 6+ it is ng build --configuration=production

Then put a production configuration in angular.json

 "configurations": {
        "production": {
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.prod.ts"
            }
          ],
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "extractCss": true,
          "namedChunks": false,
          "aot": true,
          "extractLicenses": true,
          "vendorChunk": false,
          "buildOptimizer": true
        }
      }