gpt4 book ai didi

Should I import 'fs' or 'node:fs' in Bun?(我应该在Bun中导入‘fs’还是‘node:FS’?)

转载 作者:bug小助手 更新时间:2023-10-25 16:24:49 30 4
gpt4 key购买 nike



I am trying to migrating my Node.js project to Bun. My project uses the 'fs' package in many places. I found many Bun migration examples where they import the 'fs' package as 'node:fs'. But importing as 'fs' works fine without any errors and performance issues.

我正在尝试将我的Node.js项目迁移到Bun。我的项目在很多地方使用了‘fs’包。我发现了许多Bun迁移示例,它们将‘fs’包导入为‘node:FS’。但是,作为“文件系统”导入可以很好地工作,没有任何错误和性能问题。


Should I leave my imports as 'fs' or change to 'node:fs' (and other packages that can be imported as 'node:...')? Are there performance differences?

我应该将我的导入保留为‘fs’还是更改为‘node:FS’(以及其他可以作为‘node:...’导入的包)?是否存在性能差异?


更多回答

No difference. Always prefer the use of node: prefix for core modules that are shipped as part of Node.

没什么不同。对于作为Node一部分提供的核心模块,始终倾向于使用node:prefix。

优秀答案推荐

I wouldn't imagine there are differences. (Try importing both and see if they're the same object with ===?)

我不认为有什么不同。(Try导入两者,看看它们是否是相同的对象,并使用=?)


You can also import fs in Node as node:fs (so as to make it clear it's an internal module), so both are compatible both ways.

您还可以将Node中的文件系统导入为node:fs(以便明确它是一个内部模块),因此两者都是双向兼容的。


更多回答

I imported them as fs and node_fs. console.log(fs === node_fs) prints true

我将它们导入为文件系统和节点文件系统。Console.log(文件系统=节点文件系统)打印TRUE

There you go then, they're the same.

那你去吧,它们是一样的。

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