【发布时间】:2020-07-16 22:58:35
【问题描述】:
我正在制作一个简单的包,可以编辑和提供数据,保存在 txt 文件中。
由于无法导入非脚本文件(JSON、txt 等),我使用的是Deno.open()。
Hello, World!
const decoder = new TextDecoder("utf-8")
const f = await Deno.open("sample.txt")
export default decoder.decode(await Deno.readAll(f)) // Hello, World!
f.close()
包单独运行正常,但在其他目录使用时出错。
test.ts(本地文件,将包加载到不同目录)
import file from "https://raw.githubusercontent.com/gnlow/deno-file-test/master/mod.ts"
console.log(file)
错误:
$ deno -V
deno 1.2.0
$ deno run --allow-read test.ts
Download https://raw.githubusercontent.com/gnlow/deno-file-test/master/mod.ts
Compile file:///var/task/__$deno$eval.ts
error: Uncaught NotFound: No such file or directory (os error 2)
at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
at Object.sendAsync ($deno$/ops/dispatch_json.ts:98:10)
at async Object.open ($deno$/files.ts:37:15)
at async https://raw.githubusercontent.com/gnlow/deno-file-test/master/mod.ts:3:11
似乎 deno 只下载脚本文件。
(generated file image)
我也只想让 deno 加载非脚本数据文件。
我该如何解决这个问题?
【问题讨论】:
-
文件确定存在吗?因为我运行相同的代码没有任何问题。查看截图:imgur.com/a/hBwoxi8
-
@Atomzwieback 我的意思是:将包加载到不同的目录中。我更清楚地编辑了我的问题。
标签: javascript typescript deno