Smip / ngx-sticky-sidebar

Angular library for making smart and high performance sticky sidebar.
MIT License
1 stars 1 forks source link

ɵɵdefineInjectable and ɵɵinject not found in '@angular/core #2

Open yann-mangin opened 4 years ago

yann-mangin commented 4 years ago

Hi, I have been trying to use this library but when trying to hook it up on my angular 6 app, I came across an issue that I believe should have disabled any users to make the library work properly. In the published library files

respectively in lines 60 and 63, the 2 native constants @angular/core 'defineInjectable' and 'inject' are renamed 'ɵɵdefineInjectable' and 'ɵɵinject'.

This results in successfully building or serving the app but with those 2 following warnings:

WARNING in ./node_modules/@smip/ngx-sticky-sidebar/fesm5/smip-ngx-sticky-sidebar.js 60:56-74
"export 'ɵɵdefineInjectable' was not found in '@angular/core'

WARNING in ./node_modules/@smip/ngx-sticky-sidebar/fesm5/smip-ngx-sticky-sidebar.js 60:148-156
"export 'ɵɵinject' was not found in '@angular/core'

The app is successfully build but since those 2 constants aren't properly defined, the application does not render on browsers as there is a javascript issue resulting directly from it.

smip-ngx-sticky-sidebar.js:60 Uncaught TypeError: Object(...) is not a function
    at smip-ngx-sticky-sidebar.js:60
    at Module../node_modules/@smip/ngx-sticky-sidebar/fesm5/smip-ngx-sticky-sidebar.js (smip-ngx-sticky-sidebar.js:62)
    at __webpack_require__ (bootstrap:78)
    at Module../src/app/app.module.ts (app.component.ts:13)
    at __webpack_require__ (bootstrap:78)
    at Module../src/main.ts (main.ts:1)
    at __webpack_require__ (bootstrap:78)
    at Object.0 (main.ts:12)
    at __webpack_require__ (bootstrap:78)
    at checkDeferredModules (bootstrap:45)

I believe this is a publishing issue due to the fact that the public.api.ts only exports the full module:

export * from './lib/ngx-sticky-sidebar.module';

I know that this should normally export everything which is defined in your module file but I have in the past came across that issue when publishing my own libraries, and I had the same issue that I am facing today with your renamed constants.

To resolve that matter, I needed to export every single components/services/directives/constants and so on... individually. In the case of your library, I believe it should be:

export * from './lib/services/sidebar.service';
export * from './lib/directives/sidebar.directive';
export * from './lib/sidebar.interface';
Smip commented 4 years ago

Hi,

I guess a problem is angular version. I found a same problem with another libraries, see https://github.com/angular/angular/issues/30413 I didn't test library with Angular 6. Today I'll do it and give you feedback.

About exports: You do not need to import directly the directive and the service to your app. NgxStickySidebarModule already exports the stickySidebar directive and when you import the module to your application it's automatically registering.