gpt4 book ai didi

javascript - Bunyan with webpack - 尝试访问已被填充的 fs

转载 作者:行者123 更新时间:2023-11-28 05:14:18 24 4
gpt4 key购买 nike

我正在尝试在基于 webpack 的应用程序中设置 Bunyan。

我有以下 webpack 配置:

  // these shims are needed for bunyan
alias: {
'dtrace-provider': path.resolve('empty-shim.js'),
"fs": path.resolve('empty-shim.js'),
'safe-json-stringify': path.resolve('empty-shim.js'),
"mv": path.resolve('empty-shim.js'),
'source-map-support': path.resolve('empty-shim.js')
}

其中empty-shim是一个空文件

以及我的记录器中定义的以下流:

{
level: "trace",
path: "/logs/trace.log"
// Logging from external libraries used by your app or very detailed application logging.
},
{
level: "debug",
path: "/logs/debug.log"
// Anything else, i.e. too verbose to be included in "info" level.
},
{
level: "info",
path: "/logs/info.log"
// Detail on regular operation.
},
{
level: "warn",
path: "/logs/warn.log"
// A note on something that should probably be looked at by an operator eventually.
},
{
level: "error",
stream: process.stderr // we pipe error also to stdout
// Fatal for a particular request, but the service/app continues
// servicing other requests. An operator should look at this soon(ish).
},
{
level: "error",
path: "/logs/error.log"
// Fatal for a particular request, but the service/app continues
// servicing other requests. An operator should look at this soon(ish).
},
{
level: "fatal",
path: "/logs/fatal.log"
// The service/app is going to stop or become unusable now.
// An operator should definitely look into this soon.
}

当我尝试访问我的记录器时,我收到此错误:

Uncaught TypeError: fs.createWriteStream is not a function
at Logger.addStream (http://localhost:8080/bundle.js:81080:28)
at http://localhost:8080/bundle.js:80958:19
at Array.forEach (native)
at new Logger (http://localhost:8080/bundle.js:80957:26)
at Function.createLogger (http://localhost:8080/bundle.js:82060:13)
at BunyanLogger.getLogger (http://localhost:8080/bundle.js:80479:18)

我认为这是因为 fs 已被填充到一个空文件。

我怎样才能让它发挥作用?

最佳答案

我通过使用 bunyan-sfdx-no-dtrace 别名作为 bunyan 的替代方案来解决这个烦恼。它是一个删除 dtrace 内容的 fork 。

这只是我的 webpack.config.js 的相关部分

module.exports = {
resolve: {
alias: {
bunyan: "bunyan-sfdx-no-dtrace"
}
}
};
<小时/>

免责声明 AFAICT 本身和 Bunyan-sfdx-no-dtrace 均未主动/正确维护,因此买家请小心。我必须处理这个问题,因为 Bunyan 是我需要的模块的子依赖项。

关于javascript - Bunyan with webpack - 尝试访问已被填充的 fs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41108089/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com