code-chunks/angular2-logger

not working with Angular 2.0 Release

Closed this issue · 10 comments

Setting this in modules config {provide: Logger}

package.json is "angular2-logger": "^0.5.0",

getting the following
`(23,11): error TS2345: Argument of type '{ imports: (typeof BrowserModule | ModuleWithProviders)[]; declarations: (typeof App | typeof Thu...' is not assignable to parameter of type 'NgModule'.
Types of property 'providers' are incompatible.
Type '({ [x: number]: undefined; provide: typeof LocationStrategy; useClass: typeof HashLocationStrateg...' is not assignable to type '(TypeProvider | ValueProvider | ClassProvider | ExistingProvider | FactoryProvider | any[])[]'.
Type '{ [x: number]: undefined; provide: typeof LocationStrategy; useClass: typeof HashLocationStrategy...' is not assignable to type 'TypeProvider | ValueProvider | ClassProvider | ExistingProvider | FactoryProvider | any[]'.
Type '{ [x: number]: undefined; provide: typeof Logger; }' is not assignable to type 'TypeProvider | ValueProvider | ClassProvider | ExistingProvider | FactoryProvider | any[]'.
Type '{ [x: number]: undefined; provide: typeof Logger; }' is not assignable to type 'any[]'.
Property 'length' is missing in type '{ [x: number]: undefined; provide: typeof Logger; }'.

ERROR in .//angular2-logger/app/core/level.ts
Module parse failed: /Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/angular2-logger/app/core/level.ts Unexpected token (9:7)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (9:7)
at Parser.pp$4.raise (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:2221:15)
at Parser.pp.unexpected (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:603:10)
at Parser.pp.expect (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:597:28)
at Parser.pp$1.parseExportSpecifiers (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:1215:10)
at Parser.pp$1.parseExport (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:1186:30)
at Parser.pp$1.parseStatement (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:719:71)
at Parser.pp$1.parseTopLevel (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:638:25)
at Parser.parse (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:516:17)
at Object.parse (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:3098:39)
at Parser.parse (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/webpack/lib/Parser.js:902:15)
at DependenciesBlock. (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/webpack/lib/NormalModule.js:104:16)
at DependenciesBlock.onModuleBuild (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
at nextLoader (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
at /Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
at Storage.finished (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
at /Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/graceful-fs/graceful-fs.js:78:16
at FSReqWrap.readFileAfterClose as oncomplete
@ ./
/angular2-logger/core.js 5:9-36

ERROR in .//angular2-logger/app/core/logger.ts
Module parse failed: /Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/angular2-logger/app/core/logger.ts Unexpected token (18:9)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (18:9)
at Parser.pp$4.raise (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:2221:15)
at Parser.pp.unexpected (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:603:10)
at Parser.pp.expect (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:597:28)
at Parser.pp$3.parseMethod (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:2071:10)
at Parser.pp$1.parseClassMethod (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:1137:25)
at Parser.pp$1.parseClass (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:1118:14)
at Parser.pp$1.parseStatement (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:697:19)
at Parser.pp$1.parseExport (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:1181:31)
at Parser.pp$1.parseStatement (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:719:71)
at Parser.pp$1.parseTopLevel (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:638:25)
at Parser.parse (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:516:17)
at Object.parse (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:3098:39)
at Parser.parse (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/webpack/lib/Parser.js:902:15)
at DependenciesBlock. (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/webpack/lib/NormalModule.js:104:16)
at DependenciesBlock.onModuleBuild (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
at nextLoader (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
at /Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
at Storage.finished (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
at /Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/graceful-fs/graceful-fs.js:78:16
at FSReqWrap.readFileAfterClose as oncomplete
@ ./
/angular2-logger/core.js 6:9-37

ERROR in .//angular2-logger/app/core/providers.ts
Module parse failed: /Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/angular2-logger/app/core/providers.ts Unexpected token (10:33)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (10:33)
at Parser.pp$4.raise (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:2221:15)
at Parser.pp.unexpected (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:603:10)
at Parser.pp$1.parseVar (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:1036:16)
at Parser.pp$1.parseVarStatement (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:917:10)
at Parser.pp$1.parseStatement (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:706:19)
at Parser.pp$1.parseExport (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:1181:31)
at Parser.pp$1.parseStatement (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:719:71)
at Parser.pp$1.parseTopLevel (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:638:25)
at Parser.parse (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:516:17)
at Object.parse (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/acorn/dist/acorn.js:3098:39)
at Parser.parse (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/webpack/lib/Parser.js:902:15)
at DependenciesBlock. (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/webpack/lib/NormalModule.js:104:16)
at DependenciesBlock.onModuleBuild (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
at nextLoader (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
at /Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
at Storage.finished (/Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
at /Users/jasontesser/dev/git/dotCMS-Desktop/node_modules/graceful-fs/graceful-fs.js:78:16
at FSReqWrap.readFileAfterClose as oncomplete
@ ./
/angular2-logger/core.js 7:9-40`

Using webpack. I assume something with it and the extension. What is the right config for webpack?

https://angular.io/docs/ts/latest/guide/webpack.html

Following that guide works correctly with Angular 2.0 release

I did :-(

In the vendor.ts I add this and it fails.

This is my webpack.config.js

`var path = require('path');
var webpack = require('webpack');
var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;

module.exports = {
devtool: 'source-map',
debug: true,

entry: {
'@angular': [
'rxjs',
'reflect-metadata',
'zone.js'
],
'common': ['es6-shim'],
'app': './src/app/main.ts',
'vendor': './src/vendor.ts'
},

output: {
path: __dirname + '/build/',
publicPath: 'build/',
filename: '[name].js',
sourceMapFilename: '[name].js.map',
chunkFilename: '[id].chunk.js'
},

resolve: {
extensions: ['','.ts','.js','.json', '.css', '.html']
},

module: {
loaders: [
{
test: /.ts$/,
loader: 'ts',
exclude: [ /node_modules/, /releases/ ]
},
{
test: /.json$/,
loader: 'json'
},
{
test: /.(css|html)$/,
loader: 'raw'
},
{
test: /.(png|jpg)$/,
loader: 'url?limit=10000'
}
]
},

plugins: [
new CommonsChunkPlugin({ names: ['@angular', 'common'], minChunks: Infinity })
],
target:'electron-renderer'
};`

humm. I guess I had to remove the exclude in the loader.

Now the error is as follows

ERROR in ./src/app/app.module.ts (24,11): error TS2345: Argument of type '{ imports: (typeof BrowserModule | ModuleWithProviders)[]; declarations: (typeof App | typeof Thu...' is not assignable to parameter of type 'NgModule'. Types of property 'providers' are incompatible. Type '({ [x: number]: undefined; provide: typeof LocationStrategy; useClass: typeof HashLocationStrateg...' is not assignable to type '(TypeProvider | ValueProvider | ClassProvider | ExistingProvider | FactoryProvider | any[])[]'. Type '{ [x: number]: undefined; provide: typeof LocationStrategy; useClass: typeof HashLocationStrategy...' is not assignable to type 'TypeProvider | ValueProvider | ClassProvider | ExistingProvider | FactoryProvider | any[]'. Type '{ [x: number]: undefined; provide: typeof Logger; }' is not assignable to type 'TypeProvider | ValueProvider | ClassProvider | ExistingProvider | FactoryProvider | any[]'. Type '{ [x: number]: undefined; provide: typeof Logger; }' is not assignable to type 'any[]'. Property 'find' is missing in type '{ [x: number]: undefined; provide: typeof Logger; }'.

OK so I added the providers like this and it worked
{provide: LoggerOptions, useValue: { level: LoggerLevel.INFO } }

BUT with just
{provide: Logger }
IT did NOT work. threw the error above

I don't think you are following the setup for Angular 2.

Make sure you follow the 0.5.0 Quickstart:

@NgModule({
    imports:      [ BrowserModule ],
    declarations: [ AppComponent ],
    bootstrap:    [ AppComponent ],
    providers:    [ Logger ] // AND THIS
})
export class AppModule { }

just FYI I was.

For whatever reason it needed
{provide: LoggerOptions, useValue: { level: LoggerLevel.INFO } },Logger

only Logger did NOT work. Only change.

This is the Angular2-Logger's Quickstart Guide:
https://github.com/code-chunks/angular2-logger

There's no {provide: Logger }.
You need to do something like:

@NgModule({
    ...
    providers:    [ Logger ] // AND THIS
})

or

@NgModule({
    ...
    providers:    [ 
        { provide: Options, useValue: { store: false } },
        Logger
    ]
})

That's why its not working for you.

Please see the guide.

i have same error !

providers: [AuthService, QuoteService, ArticleService, AdminService, ToolService, AuthGuard,

        {
            provide: HTTP_INTERCEPTORS, BrowserXhr, SWIPER_CONFIG,
            useClass: TokenInterceptorService, NgProgressBrowserXhr,
            useValue: {
                direction: 'horizontal',
                slidesPerView: 'auto'
            },
            multi: true,
        }
    ],

i user the true way for useValue ! but not work .

this is my error

ERROR in src/app/app.module.ts(141,41): error TS2345: Argument of type '{ declarations: (typeof TestComponent | typeof AppComponent | typeof SnackBarComponent | typeof Q...' is not assignable to parameter of type 'NgModule'.
  Types of property 'providers' are incompatible.
    Type '(typeof ToolService | typeof AuthService | typeof QuoteService | typeof AdminService | typeof Aut...' is not assignable to type 'Provider[]'.
      Type 'typeof ToolService | typeof AuthService | typeof QuoteService | typeof AdminService | typeof Auth...' is not assignable to type 'Provider'.
        Type '{ provide: InjectionToken<HttpInterceptor[]>; BrowserXhr: typeof BrowserXhr; SWIPER_CONFIG: Injec...' is not assignable to type 'Provider'.
          Object literal may only specify known properties, and 'BrowserXhr' does not exist in type 'Provider'.