gpt4 book ai didi

javascript - 无法用Electron写入文件

转载 作者:行者123 更新时间:2023-12-03 12:36:49 27 4
gpt4 key购买 nike

尝试使用Electron编写一个简单的日志文件,在开发时可以正常工作,但在打包应用程序后失败

logFilePath = path.join(app.getPath('userData'), 'output/' + moment().format('YYYYMMDD') + '.log'),
logger = fs.createWriteStream(logFilePath, {flags: 'a+'});
和用于解压缩文件的package.json部分看起来像这样
    "asarUnpack": [
"./output/*"
],
错误消息是ENOENT:没有这样的文件或目录

最佳答案

为什么第一行末尾有逗号?
在不使用逗号的情况下运行代码并声明变量:

let logFilePath = path.join(app.getPath('userData'), 'output/' + moment().format('YYYYMMDD') + '.log')
console.log('logFilePath', logFilePath);

let logger = fs.createWriteStream(logFilePath, {flags: 'a+'});
console.log('logger', logger);
logFilePath /Users/xxx/Library/Application Support/file-launcher/output/20210318.log

logger WriteStream {
_writableState: WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
afterWriteTickInfo: null,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
emitClose: false,
autoDestroy: false,
bufferedRequestCount: 0,
corkedRequestsFree: {
next: null,
entry: null,
finish: [Function: bound onCorkedFinish]
}
},
writable: true,
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
path: '/Users/xxx/Library/Application Support/file-launcher/output/20210318.log',
fd: null,
flags: 'a+',
mode: 438,
start: undefined,
autoClose: true,
pos: undefined,
bytesWritten: 0,
closed: false
}

关于javascript - 无法用Electron写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66688331/

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