Platform: ng-packagr not working with ngrx project

Created on 26 Jan 2018  路  1Comment  路  Source: ngrx/platform


sample app ngrx-with-ng-packgr.zip

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ x] Bug report  
[ ] Feature request
[ ] Documentation issue or request

What is the current behavior?


ng-packagr is not working

PS Z:\rupesh\rnd\angular\ngrx-with-ng-packgr\my-app> ng-packagr
Building Angular library
Generating bundle for my-app
Cleaning bundle build directory
Processing assets
Running ngc

BUILD ERROR
Error at Z:/rupesh/rnd/angular/ngrx-with-ng-packgr/my-app/.ng_pkg_build/my-app/ts/src/app/app.component.ts:34:14: Exported variable 'getProductState' has or is using name 'MemoizedSelector' from external module "Z:/rupesh/rnd/angular/ngrx-with-ng-packgr/my-app/node_modules/@ngrx/store/src/selector" but cannot be named.
Error: Error at Z:/rupesh/rnd/angular/ngrx-with-ng-packgr/my-app/.ng_pkg_build/my-app/ts/src/app/app.component.ts:34:14: Exported variable 'getProductState' has or is using name 'MemoizedSelector' from external module "Z:/rupesh/rnd/angular/ngrx-with-ng-packgr/my-app/node_modules/@ngrx/store/src/selector" but cannot
be named.
    at new UserError (C:\Users\rtiwari\AppData\Roaming\npm\node_modules\ng-packagr\node_modules\@angular\tsc-wrapped\src\tsc.js:27:28)
    at check (C:\Users\rtiwari\AppData\Roaming\npm\node_modules\ng-packagr\node_modules\@angular\tsc-wrapped\src\tsc.js:93:15)
    at Tsc.typeCheck (C:\Users\rtiwari\AppData\Roaming\npm\node_modules\ng-packagr\node_modules\@angular\tsc-wrapped\src\tsc.js:173:9)
    at C:\Users\rtiwari\AppData\Roaming\npm\node_modules\ng-packagr\node_modules\@angular\tsc-wrapped\src\main.js:122:23
    at <anonymous>

Expected behavior:


ng-packagr should create package successfully like it does for angular project without ngrx.

Minimal reproduction of the problem with instructions:


Please download the ngrx-with-ng-packgr.zip
zip project and then run

npm install
ng-packagr

Version of affected browser(s),operating system(s), npm, node and ngrx:

Browser: Chrome, OS : Windows 2010 , npm 5.6.0, node v8.9.4, ngrx 5.0.1, typescript: ~2.5.3

Other information:

As per Microsoft/TypeScript#9944, I also upgraded my typescript version to typescript@next still i am getting the issue.
Please let me know where I am missing something. Also is their any other option to create a package for ngrx project which I can use as npm module. I also created one more issue in ng-packagr not sure where this bug is https://github.com/dherges/ng-packagr/issues/542 It seems that even though we are exporting the MemoizedSelector it is not working properly https://github.com/ngrx/platform/pull/57

Most helpful comment

Hi I created an issue in ng-packagr github https://github.com/dherges/ng-packagr/issues/542
It seems it is not ngrx issue therefore i am closing this issue. I solved this issue by the recommendation of Danny Blue . Here is the working solution, basically we have to explicitly export the types.
If you are using @ngrx/entity then please make sure you import their types and use them in order to compile using ng-packagr.

import { MemoizedSelector } from '@ngrx/store/src/selector';
import { Dictionary, EntitySelectors } from '@ngrx/entity/src/models';
const entityFns = fromProductsAdapter.getSelectors(getProductEntitiesState);
export const {
    selectIds: getProductIds,
    selectAll: getAllProducts,
    selectTotal: getTotalProducts,
  } = entityFns;
export const getProductState: MemoizedSelector<any, any> = createFeatureSelector<any('products');
export const {selectEntities: getProductEntities}: EntitySelectors<Product, any> = entityFns;

https://github.com/roopkt/angular-ngrx-using-ng-packagr

>All comments

Hi I created an issue in ng-packagr github https://github.com/dherges/ng-packagr/issues/542
It seems it is not ngrx issue therefore i am closing this issue. I solved this issue by the recommendation of Danny Blue . Here is the working solution, basically we have to explicitly export the types.
If you are using @ngrx/entity then please make sure you import their types and use them in order to compile using ng-packagr.

import { MemoizedSelector } from '@ngrx/store/src/selector';
import { Dictionary, EntitySelectors } from '@ngrx/entity/src/models';
const entityFns = fromProductsAdapter.getSelectors(getProductEntitiesState);
export const {
    selectIds: getProductIds,
    selectAll: getAllProducts,
    selectTotal: getTotalProducts,
  } = entityFns;
export const getProductState: MemoizedSelector<any, any> = createFeatureSelector<any('products');
export const {selectEntities: getProductEntities}: EntitySelectors<Product, any> = entityFns;

https://github.com/roopkt/angular-ngrx-using-ng-packagr

Was this page helpful?
0 / 5 - 0 ratings