TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be one of type string, Buffer, TypedArray, or DataView. Received type undefined

发布时间:2020-05-19 20:33:10.23编辑:佚名阅读(358)

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be one of type string, Buffer, TypedArray, or DataView. Received type undefined

原因:

Node后端 express框架,代码如下:

app.get(path, function(req, resp) {
  // ...
  resp.write(somethind);
});

要写回浏览器页面的数据something的类型不是string或Buffer(可能是一个对象)。
转换类型即可:

resp.write(JSON.stringify(something));

将something对象字符串化。

  关键字:TypeErrorERR_INVALID_ARG_TYPEThe data argument must be one of type stringBufferTypedArrayor DataViewReceived type undefined


鼓掌

1

正能量

0

0

呵呵

0


评论区