darekf77 / ng2-logger

Isomorphic logger for Browser and NodeJS, ( typescript / javascript ) apps
MIT License
61 stars 17 forks source link

fs issue with karma, maybe need to update the document #30

Closed xmeng1 closed 6 years ago

xmeng1 commented 6 years ago

Because ng2-logger require 'fs', and ng test fails Module not found: Error: Can't resolve 'fs' (see this issue https://github.com/angular/angular-cli/issues/8357 and this https://github.com/webpack-contrib/css-loader/issues/447. Maybe need to update the document and let user add configuration to the karma.conf.js if the user wants to use karma to test angular.

module.exports = function (config) {
  config.set({
    webpack: { node: { fs: 'empty', } },
    basePath: '',
    ......
darekf77 commented 6 years ago

ng2-logger doesn't require 'fs' use 'ng2-logger/browser'

jimmykane commented 6 years ago

Getting the same error btw after updating to AG6

jimmykane commented 6 years ago

@darekf77 nope you are wrong it does https://github.com/darekf77/ng2-logger/blob/3cebe387612d25c48ea5348742672017f89bb4fa/src/backend-logging.ts#L14

darekf77 commented 6 years ago

@jimmykane check if somewhere in your code you are not refering to ng2-logger instead of ng2-logger/browser

jimmykane commented 6 years ago

@darekf77 just a few mins ago solved this. I was indeed using the ng2-logger but not correct. I had -import {Log, Level} from 'ng2-logger' while it should have been +import {Log, Level} from 'ng2-logger/client'

Thanks for looking into this

tianchez commented 6 years ago

@darekf77 Got the error after upgrading to Angular 6. I was using import {Log, Level} from 'ng2-logger'. After changing to import {Log, Level} from 'ng2-logger/client' or import {Log, Level} from 'ng2-logger/browser', ng serve is working but not for ng build. Do you have any solution?

tianchez commented 6 years ago

@jimmykane Is your solution working for you when running ng build?

jimmykane commented 6 years ago

@tianchez yup. Only import from client

darekf77 commented 6 years ago

@tianchez with ng build AOT is enable by default... try without AOT... In next week I am going to release version with AOT support - with proper package.json and js modules produced by https://github.com/dherges/ng-packagr.

jimmykane commented 6 years ago

@darekf77 I am building for prod and it's ok. (AOT enabled)

tianchez commented 6 years ago

@darekf77 You are right. It works without AOT for me. To be specific, I got this error when building with ng build --prod

screen shot 2018-05-09 at 4 13 04 pm

However, if I build with ng build --prod --aot=false --build-optimizer=false, no errors showing up

zapphyre commented 6 years ago

I'm using Angular @angular/core": "^6.0.3 with @angular/cli": "~6.0.7 and I'm getting:

ERROR in ./node_modules/ng2-logger/backend-logging.js
Module not found: Error: Can't resolve 'fs' in '/home/tepo/IdeaProjects/OneDMS-GUI/node_modules/ng2-logger'
ERROR in ./node_modules/ng2-logger/display.js
Module not found: Error: Can't resolve 'path' in '/home/tepo/IdeaProjects/OneDMS-GUI/node_modules/ng2-logger'
ERROR in ./node_modules/ng2-logger/backend-logging.js
Module not found: Error: Can't resolve 'path' in '/home/tepo/IdeaProjects/OneDMS-GUI/node_modules/ng2-logger'
ℹ 「wdm」: Failed to compile.

when I run ng serve I'm importing from client: import {Log} from 'ng2-logger/client'