2017-02-26 70 views
0

我想配置我的Bunyan記錄器NodeJS項目。這種配置工作正常,直到我開始將我的項目轉換爲Typescript。Bunyan記錄器typescript配置Errror命名記錄器不能命名

這裏是我的配置記錄儀在文件MyLogger.ts配置功能:

import { createWriteStream } from 'fs' 
import { stdSerializers, createLogger } from 'bunyan' 
const pkg = require('../../package.json') 

export default function (logLevel: string = 'debug', logFolder: string) { 
    const logOptions = { 
    serializers: stdSerializers, 
    name: `${pkg.name}-${pkg.version}`, 
    streams: [ 
     { level: 'error', stream: process.stderr }, 
     { level: logLevel, stream: process.stdout } 
    ] 
    } 

    if (logFolder) { 
    logOptions.streams.push(
     { level: logLevel, stream: createWriteStream(`${logFolder}/${pkg.name}.log`) }) 
    } 

    const logger = createLogger ({ 
    name: logOptions.name, 
    streams: logOptions.streams 
    }) 

    return logger 
} 

現在當我編譯打字稿,我得到以下錯誤:

lib/config/MyLogger.ts(5,1): error TS4058: Return type of exported function has or is using name 'Logger' from external module "project-folder/node_modules/@types/bunyan/index" but cannot be named.

我使用節點版本:6.9.2 Bunyan版本:1.8.5 @ types/bunyan「:」0.0.35

任何幫助理解錯誤或者如何解決這個問題..會很好。 謝謝。

回答

0

基礎上,打字稿問題在這裏:TS4023

我通過增加進口作爲運行編譯:

import * as Logger from '@types/bunyan' 

,然後addding返回類型我導出功能Logger