【问题标题】:Property 'Azure' does not exist on type 'Transports' for winston温斯顿的“传输”类型上不存在属性“Azure”
【发布时间】:2018-06-16 01:37:16
【问题描述】:
    var winston = require("winston");
    require("winston-azure-blob-transport"); 
    var logger = new (winston.Logger)({
        transports: [
            new (winston.transports.AzureBlob)({
                account: {
                    name: "Azure storage account sub domain ([A-Za-z0-9])",
                    key: "The long Azure storage secret key"
                },
                containerName: "A container name",
                blobName: "The name of the blob",
                level: "info"
            })
        ]
    });
    logger.warn("Hello!");

我收到一个错误,即“传输”类型上不存在属性“Azure”

【问题讨论】:

  • 您是否使用npm install winston-azure-blob-transport 安装了winston-azure-blob-transport ?
  • 是的,我已经安装了它
  • 您使用的是哪个版本的 Winston?你能提供你的 package.json 吗?
  • "winston": "^2.4.0", "winston-azure-blob-transport": "^0.2.6", "winston-daily-rotate-file": "^1.7. 2", "winston-express-middleware": "^0.1.0"

标签: node.js winston azure-blob-storage


【解决方案1】:

我仍然无法使用您提供的代码重现此问题。

这是我的package.json 文件:

{
  "name": "testwinston",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "winston": "^2.4.0",
    "winston-azure-blob-transport": "^0.2.6",
    "winston-daily-rotate-file": "^1.7.2", 
    "winston-express-middleware": "^0.1.0"
  }
}

这是我正在使用的代码:

var winston = require("winston");
require("winston-azure-blob-transport"); 

var logger = new (winston.Logger)({
    transports: [
        new (winston.transports.AzureBlob)({
            account: {
                name: "<my storage account name>",
                key: "my account key"
            },
            containerName: "test-container",
            blobName: "testlog.txt",
            level: "info"
        })
    ]
});
logger.warn("Hello!");

然后会创建一个包含以下内容的 blob 文件:

【讨论】:

  • 我还可以在 blob 存储中创建文件,但我正在使用 typescript 我收到错误,即 [ts] 属性 'AzureBlob' 在类型'Transports' 上不存在。很抱歉之前没有提及。
猜你喜欢
  • 2014-12-10
  • 2013-05-15
  • 1970-01-01
  • 2019-10-28
  • 2013-10-23
  • 2016-08-29
  • 1970-01-01
  • 2016-12-13
  • 2018-11-19
相关资源
最近更新 更多