better-js-logging / angular-logger2

Proper logging in Typescript or Angular2+, including patterns and level management
Apache License 2.0
2 stars 2 forks source link

Rxjs Errors with Angular 6x #6

Open jderus opened 6 years ago

jderus commented 6 years ago

Since I liked it so much in Angular 4-5, I was attempting to use this package (v1.1.0) with Angular 6x (core: ^6.0.3, cli: ~6.0.8, rxjs: ^6.0.0). I got the following:

ERROR in ./node_modules/angular-logger2/node_modules/@angular/core/esm5/core.js
Module not found: Error: Can't resolve 'rxjs/Observable' in 'E:\MyProject\node_modules\angular-logger2\node_modules\@angular\core\esm5'
ERROR in ./node_modules/angular-logger2/node_modules/@angular/core/esm5/core.js
Module not found: Error: Can't resolve 'rxjs/Subject' in 'E:\MyProject\node_modules\angular-logger2\node_modules\@angular\core\esm5'
ERROR in ./node_modules/angular-logger2/node_modules/@angular/core/esm5/core.js
Module not found: Error: Can't resolve 'rxjs/Subscription' in 'E:\MyProject\node_modules\angular-logger2\node_modules\@angular\core\esm5'
ERROR in ./node_modules/angular-logger2/node_modules/@angular/core/esm5/core.js
Module not found: Error: Can't resolve 'rxjs/observable/merge' in 'E:\MyProject\node_modules\angular-logger2\node_modules\@angular\core\esm5'
ERROR in ./node_modules/angular-logger2/node_modules/@angular/core/esm5/core.js
Module not found: Error: Can't resolve 'rxjs/operator/share' in 'E:\MyProject\node_modules\angular-logger2\node_modules\@angular\core\esm5'

Here is what I saw in my package-lock.json file:

    "angular-logger2": {
      "version": "1.1.0",
      "resolved": "https://registry.npmjs.org/angular-logger2/-/angular-logger2-1.1.0.tgz",
      "integrity": "sha512-LqYkkEuNDQC0hVTxYkOGhPdRZaq9YDGIEzzpyDYPWUeKO1wu62O/xAHzO+UfFAxW78XQVDrjLFdu9SOs5UkFzQ==",
      "requires": {
        "@angular/core": "5.2.11",
        "moment": "2.22.2",
        "sprintf-js": "1.1.1"
      },

That didn't seem to match the 6.0.3 core in the repo package.json.

To me, this looked like breaking changes in rxjs as of 6x, so I quickly hacked the imports in node_modules to see if it would mitigate. That got everything to build, but then I encountered: #5

WARNING in ./node_modules/angular-logger2/node_modules/@angular/core/esm5/core.js
6570:15-36 Critical dependency: the request of a dependency is an expression

This seems to be related to this zombie thread here: https://github.com/webpack/webpack/issues/196

Should we be expecting 1.1.0 to work with Angular 6 out of the box?

bbottema commented 6 years ago

It's supposed to, but Angular/Webpack introduced some changes that break existing dependant projects, including this one.

I'm not sure what the fix is for #5. I tried a few vague proposed solutions, but I was unable to get a definitive success.

I would love to get it fixed, but I'm going to need some help with that because honestly, I'm still having trouble understanding the whole "the request of a dependency is an expression" situation. That zombie thread you mentioned is all over the place as well.

jderus commented 6 years ago

Yeah, that thread is definitely all over - which should be a good clue that webpack errors could be more robust :) My bigger concern here is why I don't seem to be pulling down a version with Angular 6 and the changes to RxJs. Is something more recent not published up to npm? (I see that your versions in package and package-lock do not match 1.1.0 and 1.2.1).

FWIW, my hack was simply a change in the import statements in core/esm5/core.js:

import { __assign, __extends } from 'tslib';
import { Observable } from 'rxjs';
import { merge } from 'rxjs/operators';
import { share } from 'rxjs/operators';
import { Subject } from 'rxjs';
import { Subscription } from 'rxjs';