Skip to content

Building library with v6 CLI only supports ng-package.json configuration filename #10710

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

Closed
cmolodo opened this issue May 7, 2018 · 2 comments · Fixed by ng-packagr/ng-packagr#886

Comments

@cmolodo
Copy link

cmolodo commented May 7, 2018

Versions

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

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.6.0
@angular-devkit/build-angular      0.6.0
@angular-devkit/build-ng-packagr   0.6.0
@angular-devkit/build-optimizer    0.6.0
@angular-devkit/core               0.6.0
@angular-devkit/schematics         0.6.0
@ngtools/json-schema               1.1.0
@ngtools/webpack                   6.0.0
@schematics/angular                0.6.0
@schematics/update                 0.6.0
ng-packagr                         3.0.0-rc.3
rxjs                               6.1.0
typescript                         2.7.2
webpack                            4.6.0

Repro steps

Production library build uses ng-package.json rather than ng-package.prod.json

  • ng new my-project
  • cd my-project
  • ng generate library my-lib
  • ng build my-lib --prod

Renaming ng-package.json causes an ng-packagr error

  • Rename ng-package.json to ng-package-dev.json (or any other desired name)
  • Modify the angular.json build.options.project setting accordingly
  • ng build my-lib

Observed behavior

The default library generation and angular.json settings imply that it's possible to use a separate ng-package.prod.json file to configure production builds of the library. However, ng-packagr seems to only recognize the file name ng-package.json. Building with the --prod flag uses ng-package.json if present, no matter what the angular.json configuration specifies. In the repro above, the built library is output to dist/my-lib rather than dist/lib. Also, if any settings such as "lib.umdId" are modified in the production configuration, those settings aren't used.

Additionally, if ng-package.json is renamed, ng-packagr throws the error below when building the library. (Note that if ng-package.json is not present, the production configuration is used, but throws the same error, specifying the production ng-package file.)

BUILD ERROR
Trying to read a package from unsupported file extension. Path=C:\src\AngularTest\my-project\projects\my-lib\ng-package-dev.json
Error: Trying to read a package from unsupported file extension. Path=C:\src\AngularTest\my-project\projects\my-lib\ng-package-dev.json
    at Object.<anonymous> (C:\src\AngularTest\my-project\node_modules\ng-packagr\lib\ng-v5\discover-packages.js:67:15)
    at Generator.next (<anonymous>)
    at fulfilled (C:\src\AngularTest\my-project\node_modules\ng-packagr\lib\ng-v5\discover-packages.js:4:58)
    at <anonymous>

Desired behavior

The ng-generated library and angular.json settings probably shouldn't include an ng-package.prod.json file or separate "production.project" configuration for building a library, since this isn't currently supported by ng-packagr.

This isn't a critical issue, since the build works fine with ng-package.json, and I don't have a specific use-case for a separate production configuration, but it is somewhat misleading.

@clydin
Copy link
Member

clydin commented Jun 19, 2018

This should be resolved via ng-packagr 4.0.0-rc.0+.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants