升级到节点 14 导致:TypeError [ERR_INVALID_ARG_TYPE]:“data”参数必须是字符串类型或 Buffer 的实例

问题描述 投票:0回答:2

我的应用程序位于 Node 12 上。我尝试将其升级到 Node 14,但收到此错误

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (94)
    at Object.writeFileSync (fs.js:1517:5)
    at writePid (/app/node_modules/forever/bin/monitor:13:6)
    at exports.Monitor.<anonymous> (/app/node_modules/forever/bin/monitor:46:5)
    at exports.Monitor.EventEmitter.emit (/app/node_modules/eventemitter2/lib/eventemitter2.js:339:22)
    at /app/node_modules/forever-monitor/lib/forever-monitor/monitor.js:177:10
    at processTicksAndRejections (internal/process/task_queues.js:77:11) {
  code: 'ERR_INVALID_ARG_TYPE'
}

我注意到我没有在应用程序中使用 fs.writeFileSync,因此我很困惑如何以及在何处触发此错误。我该如何调试这个?

node.js fs
2个回答
1
投票

fs.writeFileSync
处理无效参数的方式发生了变化(https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options并展开历史记录以查看更改)

在 v14 之前,它会默默地将

data
不支持的类型转换为字符串。看来现在会抛出错误。并且您安装的forever版本会发送
number
作为不支持的数据。因此出现错误。更新到forever最新版本。

编辑还请记住永远项目页面上的以下评论

一个简单的 CLI 工具,用于确保给定的脚本连续运行(即永远)。请注意,该项目目前完全依赖社区来实现修复和新功能。对于新安装,我们鼓励您使用 pm2 或 nodemon


0
投票

您使用永久版本< 3.0.0. To use forever with nodejs version >= 14.x.x,您必须至少永久升级到v3.0.0。通过测试,这个错误已在 v3.0.0 中修复,尽管作者没有在变更日志中提及:https://github.com/foreversd/forever/blob/master/CHANGELOG.md#300--fri-22-may-2020

请注意,在nodejs => 14.x.x上使用forever,你会看到警告

Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
,但forever正在工作。

© www.soinside.com 2019 - 2024. All rights reserved.