angular2-logger icon indicating copy to clipboard operation
angular2-logger copied to clipboard

getting Error in angular 5.0

Open Sathishchary opened this issue 8 years ago • 17 comments

HI, I am converting my angular project form 4.3 to 5.0 ,, I installed the"angular2-logger": "^0.6.0", but its not working in 5.0 I got below error.

ERROR in ./node_modules/angular2-logger/app/core/level.ts Module build failed: Error: C:\Users\ksath\Documents\POC\ProjectCli\newProject\node_modules\angular2-logger\app\core\level.t s is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. at AngularCompilerPlugin.getCompiledFile (C:\Users\ksath\Documents\POC\ProjectCli\newProject\node_modules@ngtools\webpa ck\src\angular_compiler_plugin.js:624:23) at plugin.done.then (C:\Users\ksath\Documents\POC\ProjectCli\newProject\node_modules@ngtools\webpack\src\loader.js:467: 39) @ ./node_modules/angular2-logger/core.js 6:9-36 @ ./src/app/app.module.ts @ ./src/main.ts @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts

can you please help.

Sathishchary avatar Nov 08 '17 06:11 Sathishchary

Somewhat similar error but on angular 4.4.4. [edit]: the very same error spotted on logger version 0.5.1.

ERROR in ./node_modules/angular2-logger/app/core/level.ts
Module build failed: Error
    at new FatalError (>>path<<\sources\node_modules\tslint\lib\error.js:31:23)
    at Linter.getSourceFile (>>path<<\sources\node_modules\tslint\lib\linter.js:204:23)
    at Linter.lint (>>path<<\sources\node_modules\tslint\lib\linter.js:72:31)
    at lint (>>path<<\sources\node_modules\tslint-loader\index.js:70:10)
    at Object.module.exports (>>path<<\sources\node_modules\tslint-loader\index.js:140:3)
 @ ./node_modules/angular2-logger/core.js 6:9-36
 @ ./src/app/module.ts
 @ ./src/main.ts
 @ multi (webpack)-dev-server/client?http://docker.for.win.localhost:4200 ./src/main.ts

ERROR in ./node_modules/angular2-logger/app/core/logger.ts
Module build failed: Error
    at new FatalError (>>path<<\sources\node_modules\tslint\lib\error.js:31:23)
    at Linter.getSourceFile (>>path<<\sources\node_modules\tslint\lib\linter.js:204:23)
    at Linter.lint (>>path<<\sources\node_modules\tslint\lib\linter.js:72:31)
    at lint (>>path<<\sources\node_modules\tslint-loader\index.js:70:10)
    at Object.module.exports (>>path<<\sources\node_modules\tslint-loader\index.js:140:3)
 @ ./node_modules/angular2-logger/core.js 7:9-37
 @ ./src/app/module.ts
 @ ./src/main.ts
 @ multi (webpack)-dev-server/client?http://docker.for.win.localhost:4200 ./src/main.ts

ERROR in ./node_modules/angular2-logger/app/core/providers.ts
Module build failed: Error
    at new FatalError (>>path<<\sources\node_modules\tslint\lib\error.js:31:23)
    at Linter.getSourceFile (>>path<<\sources\node_modules\tslint\lib\linter.js:204:23)
    at Linter.lint (>>path<<\sources\node_modules\tslint\lib\linter.js:72:31)
    at lint (>>path<<\sources\node_modules\tslint-loader\index.js:70:10)
    at Object.module.exports (>>path<<\sources\node_modules\tslint-loader\index.js:140:3)
 @ ./node_modules/angular2-logger/core.js 8:9-40
 @ ./src/app/module.ts
 @ ./src/main.ts
 @ multi (webpack)-dev-server/client?http://docker.for.win.localhost:4200 ./src/main.ts

wojtuch avatar Nov 09 '17 14:11 wojtuch

@Sathishchary I ran into the same problem after upgrading to Angular 5.x. If you go to node_modules\angular2-logger\app\core and remove all of the .ts files in there it will temporarily fix the problem. We need to get a build of this library without the source included in it to fully fix the problem.

MitekDev-Mcalvin avatar Nov 10 '17 20:11 MitekDev-Mcalvin

I'm not going to have time for a while to go into this, but I'll review PRs if receive any. However if angular was what got upgraded and then it started failing, then it sounds to me like an Angular issue.

langley-agm avatar Nov 10 '17 20:11 langley-agm

I will try and get some time this weekend to help out if I can. It appears that Angular is following Typescripts standards for tsconfig more strictly (blog entry) and there is also more conversation about the problem (as well as some things you can try and do to solve it) here. @langley-agm Thanks for putting this library together, I use it a ton, and am happy to help out if I can.

MitekDev-Mcalvin avatar Nov 10 '17 20:11 MitekDev-Mcalvin

Even I have the same error

appdevchicago avatar Nov 21 '17 02:11 appdevchicago

Probably related angular issue https://github.com/angular/angular-cli/issues/8284#issuecomment-341417325

You have TS files in your node_modules. This really goes against how libraries should be packaged: libraries should never ship their source .ts files.

abngal avatar Nov 28 '17 22:11 abngal

"This really goes against how libraries should be packaged: libraries should never ship their source .ts files"

I'm not so sure who started stating this crazy idea as a fact, but I'm pretty sure it only started until Typescript started making things harder by not defining standards, not only npm is way newer than other builders to call the shots at what the standard should be but I haven't seen a single source from them stating something like that and many other builders allow you to select whether you want the source included or not, why would this option exist if libraries should never ship their source files?

For reference if you install RxJS you'll see the src files and Angular uses RxJS, or at least they did last time I checked.

Just to clarify, I'm not against removing them, I don't believe that's the correct solution because I've found it incredibly helpful in the past to have the src files in my third party libraries, but I don't mind considering it if its affecting many people. However I do not have the time to research this atm to find a real solution and the fact that they keep changing the structure/standards every couple of months doesn't help. However, like I mentioned before anyone's welcome to publish a PR and I'll take a look at it even if it fixes it by removing the src files.

langley-agm avatar Nov 28 '17 23:11 langley-agm

As the error states, you need to include a reference to the Typescript files that are imported by angular2-logger so TypeScript is aware of them. Edit the tsconfig.json (or tsconfig.app.json if you're using the angular cli) to include the following snippet:

"include": [
    "../node_modules/angular2-logger/app/core/level.ts",
    "../node_modules/angular2-logger/app/core/logger.ts",
    "../node_modules/angular2-logger/app/core/providers.ts",
    "**/*.ts"
],

Aitchy13 avatar Nov 30 '17 14:11 Aitchy13

@Aitchy13 I tried this. Doesnt work for me.

pankajsri03 avatar Dec 04 '17 05:12 pankajsri03

Worked for me.

elendil-software avatar Dec 04 '17 06:12 elendil-software

Hi, @Aitchy13 workaround worked for me too. Thanks a lot.

ricforaf avatar Dec 13 '17 08:12 ricforaf

Hi, thanks @Aitchy13, you saved me a lot of time !

OlivierCadoz avatar Jan 09 '18 08:01 OlivierCadoz

@Aitchy13 's method is worked for "ng serve" for me ,but not for "ng --prod --aot". so i copy the code into my project

FreezeSoul avatar Jan 31 '18 02:01 FreezeSoul

@FreezeSoul Aitchy13's solution is worked for me,not only 'ng serve',but also 'ng build --prod --aot',maybe cause I add extra solution from stack overflow ,maybe it helps

Eve-Sama avatar Mar 14 '18 07:03 Eve-Sama

Solution that worked for me. the installed package has a dist dir node_modules/angular2-logger/dist/es6/.

in node_modules/angular2-logger/package.json main is set to

"main": "./dist/cjs/core.js",

change this to

"main": "./dist/es6/core.js",

You may have a different dir structure as dist is created during installation process. So the goal shouls be to point main to compiled core.js file.

Change all the import statements for Logger to

import { Logger } from 'angular2-logger';

Compile and run and stay happy.

I don't know wheather this is a typo or delibrate decision, but this works even for ng build --prod

pyarun avatar Mar 28 '18 08:03 pyarun

Aitchy13 worked for me, your really help me

prudvi avatar May 22 '18 07:05 prudvi

Same issue here however I'd like to avoid workarounds.

Hagalas avatar Jun 20 '18 10:06 Hagalas