TypeError:FS.CreateWritestream不是节点中的功能
我找不到任何资源在线解释为什么我遇到这个问题,即使官方节点js doc / api参考说createwritestream是fs中的一种方法:
fs.CreateWriteStream(路径[,options])[src]#
我发现的所有其他堆栈溢出问题都是不小心试图从浏览器访问FS的人。 因此,为了澄清,我正在使用节点!!
示例代码:
import fs from 'fs/promises'
let ws = fs.createWriteStream("example.png")
示例代码输出:
file:///workspace/buz/src/error.js:3
let ws = fs.createWriteStream("example.png")
^
TypeError: fs.createWriteStream is not a function
at file:///workspace/buz/src/error.js:3:13
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)
节点版本: v16.15.1
OS: Mac OS
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我弄清楚了:
createWriteStream()
是 fs 的函数,但不是 fs/promise !我找不到任何文档在线上如何使用FS Prosiss使用
createWriteStream()
,因此最简单的选择只是从基于正常回调的FS:我读到节点文档通过
fs/Promises
API中的所有方法,它们都没有返回< writestream>
。因此,到目前为止,如果没有从普通fs
api导入内容的情况下,似乎无法解决这个问题。更新:在描述基于回调的FS API 时,更改措辞以不使用单词同步
I figured it out:
createWriteStream()
is a function of fs, but not of fs/promises!!I couldn't find ANY documentation online for how to use
createWriteStream()
with fs promises, so the easiest option is just to import it from the normal callback based fs:I read through the Node documentation on
fs
and went through all the methods in the thefs/promises
API and none of them return a<WriteStream>
. So as of today, it seems like there's no way to get around this issue without importing stuff from the normalfs
API.Update: Changed wording to not use the word synchronous when describing the callback based fs API
如果您想使用FS/Promise。首先,您应该打开文件以获取文件打架。然后,您可以使用fileHanlde.CreateWriteStream()。
if you want use fs/promise. First, you should open file to get a FileHandle. then you can use fileHanlde.createWriteStream().