angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Unsupported private class error doesn't throw on building library for production

Open robertIsaac opened this issue 5 years ago • 6 comments

🐞 Bug report

Command (mark with an x)

  • [ ] new
  • [x] build
  • [ ] serve
  • [ ] test
  • [ ] e2e
  • [ ] generate
  • [ ] add
  • [ ] update
  • [ ] lint
  • [ ] xi18n
  • [ ] run
  • [ ] config
  • [ ] help
  • [ ] version
  • [ ] doc

Is this a regression?

i'm not sure

Description

when i export a component in the library module but not in the public API the build command throw errors only in normal mode, but in production mode it completes successfully

🔬 Minimal Reproduction

clone https://github.com/robertIsaac/test-library and run ng b and ng b --prod

or generate from scratch

ng new test-library --create-application=false
cd test-library
ng generate library test-library
ng g c test-export --export
ng b
ng b --prod

🔥 Exception or Error

both commands should throw the following error


Unsupported private class TestExportComponent. This class is visible to consumers via TestLibraryModule -> TestExportComponent, but is not exported from the top-level library entrypoint.

🌍 Your Environment


$ ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 9.1.1
Node: 12.14.1
OS: win32 x64

Angular: 9.1.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.901.1
@angular-devkit/build-angular      0.901.1
@angular-devkit/build-ng-packagr   0.901.1
@angular-devkit/build-optimizer    0.901.1
@angular-devkit/build-webpack      0.901.1
@angular-devkit/core               9.1.1
@angular-devkit/schematics         9.1.1
@angular/cli                       9.1.1
@ngtools/webpack                   9.1.1
@schematics/angular                9.1.1
@schematics/update                 0.901.1
ng-packagr                         9.1.1
rxjs                               6.5.5
typescript                         3.8.3
webpack                            4.42.0

Anything else relevant?

it would be nice if --export command also update the public api file if it's running inside a library

robertIsaac avatar Apr 21 '20 12:04 robertIsaac

@robertIsaac, the problem here is that the above is only an error when using Ivy rendering engine, with View Engine which is used for production builds, this is valid.

That said, we should add the export to the public api when using the schematics so that we generate valid code for both rendering engines.

alan-agius4 avatar Apr 21 '20 14:04 alan-agius4

Any news?`i sitll have this issue on a new generated project with angular version 13.1.0

SvenBudak avatar Feb 04 '22 15:02 SvenBudak

@nhhockeyplayer, please refrain from spamming. It appears that you are experience issues unrelated to the original issue reported here. Ie ng generate inside a library project.

I saw two errors in your comments

node_modules/@meanstacknh/shared-ui-widget/shared-ui-widget.module.ts:28:9 - error NG3004: Unable to import class DirectivesModule.
     The file /Users/meanstack02/meanstacknh/node_modules/@meanstacknh/shared-ui-widget/directives/directives.module.ts is outside of the configured 'rootDir'.

The above indicates that you are trying to access a file outside of the root directory of your library. Start by checking and validating that you are importing the files correctly.

Module '"@meanstacknh/shared-ui-widget/shared-ui-widget.module"' declares 'DirectivesModule' locally, but it is not exported

This indicates that DirectivesModule is not exported as part of the libraries public api.


If the issue persists please open a new issue and provide a minimal reproduction.

You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

This might be related to your directory structure so its really important to get an accurate repro to diagnose this.

alan-agius4 avatar Jul 04 '22 12:07 alan-agius4

@alan-agius4 i think you mark the wrong one. nhhockeyplayer is spamming, not me. 😂

SvenBudak avatar Jul 04 '22 13:07 SvenBudak

Oh apologies :)

alan-agius4 avatar Jul 04 '22 13:07 alan-agius4

Do we need to add all exports in public.api.ts or any other work around after angular 12.

Amit221060 avatar Oct 06 '23 08:10 Amit221060