我正在尝试使用标准 deno fs 模块,但编译器抱怨没有--unstable标志。
import { writeJson, readJson } from "https://deno.land/std/fs/mod.ts";
const json = await readJson("input.txt");
console.log(`JSON: ${JSON.stringify(json)}`);
await writeJson("input.txt", json);
Run Code Online (Sandbox Code Playgroud)
我的 deno 版本:
deno 1.0.0-rc2
v8 8.4.300
typescript 3.8.3
Run Code Online (Sandbox Code Playgroud)
我总是遇到相同的错误。它们似乎与缺少模块有关,但我不确定可能缺少什么。
? deno-api denoa filetest.ts
Compile file:///home/astone/source/deno-api/filetest.ts
error: TS2339 [ERROR]: Property 'utime' does not exist on type 'typeof Deno'.
await Deno.utime(dest, statInfo.atime, statInfo.mtime);
~~~~~
at https://deno.land/std/fs/copy.ts:90:16
TS2339 [ERROR]: Property 'utimeSync' does not exist on type 'typeof Deno'.
Deno.utimeSync(dest, statInfo.atime, statInfo.mtime);
~~~~~~~~~
at https://deno.land/std/fs/copy.ts:101:10
TS2339 [ERROR]: Property 'symlink' does not exist on type 'typeof Deno'.
await Deno.symlink(originSrcFilePath, dest, type);
~~~~~~~
at https://deno.land/std/fs/copy.ts:114:14
TS2339 [ERROR]: Property 'utime' does not exist on type 'typeof Deno'.
await Deno.utime(dest, statInfo.atime, statInfo.mtime);
~~~~~
at https://deno.land/std/fs/copy.ts:119:16
TS2339 [ERROR]: Property 'symlinkSync' does not exist on type 'typeof Deno'.
Deno.symlinkSync(originSrcFilePath, dest, type);
~~~~~~~~~~~
at https://deno.land/std/fs/copy.ts:132:8
TS2339 [ERROR]: Property 'utimeSync' does not exist on type 'typeof Deno'.
Deno.utimeSync(dest, statInfo.atime, statInfo.mtime);
~~~~~~~~~
at https://deno.land/std/fs/copy.ts:137:10
TS2339 [ERROR]: Property 'utime' does not exist on type 'typeof Deno'.
await Deno.utime(dest, srcStatInfo.atime, srcStatInfo.mtime);
~~~~~
at https://deno.land/std/fs/copy.ts:157:16
TS2339 [ERROR]: Property 'utimeSync' does not exist on type 'typeof Deno'.
Deno.utimeSync(dest, srcStatInfo.atime, srcStatInfo.mtime);
~~~~~~~~~
at https://deno.land/std/fs/copy.ts:185:10
TS2339 [ERROR]: Property 'link' does not exist on type 'typeof Deno'.
await Deno.link(src, dest);
~~~~
at https://deno.land/std/fs/ensure_link.ts:28:14
TS2339 [ERROR]: Property 'linkSync' does not exist on type 'typeof Deno'.
Deno.linkSync(src, dest);
~~~~~~~~
at https://deno.land/std/fs/ensure_link.ts:52:8
TS2339 [ERROR]: Property 'symlink' does not exist on type 'typeof Deno'.
await Deno.symlink(src, dest, srcFilePathType);
~~~~~~~
at https://deno.land/std/fs/ensure_symlink.ts:31:14
TS2339 [ERROR]: Property 'symlinkSync' does not exist on type 'typeof Deno'.
Deno.symlinkSync(src, dest, srcFilePathType);
~~~~~~~~~~~
at https://deno.land/std/fs/ensure_symlink.ts:58:8
Found 12 errors.
Run Code Online (Sandbox Code Playgroud)
如果我只导入 readJson 模块,那么我不会出错。
deno 1.0.0-rc2
v8 8.4.300
typescript 3.8.3
Run Code Online (Sandbox Code Playgroud)
我尝试使用标签构建,但我似乎无法弄清楚1.0.0-rc2. 我试过了https://deno.land/std@0.50.0/fs/mod.ts。
Deno.utime已被标记为不稳定,这就是您应该使用--unstableflag的原因
还有一个悬而未决的问题:属性 'utime' 在类型 'typeof Deno' 上不存在此错误。
目前有多个API 位于不稳定标志后面。
从 Deno 1.0.0 开始,Deno 命名空间 API 是稳定的。这意味着我们将努力使在 1.0.0 下工作的代码在未来版本中继续工作。
但是,并非 Deno 的所有功能都已准备好投入生产。由于仍处于草案阶段而未准备好的功能被锁定在 --unstable 命令行标志后面。
正在使用的文件Deno.utime是copy.ts&ensure_symlink.ts这就是为什么如果你只加载read_json.ts你不会得到那个错误,并且不需要不稳定标志的原因。
最新的标签std/是std/0.50.0但是你总是可以直接将 github 存储库引用到你想要的任何提交或发布标签。
https://raw.githubusercontent.com/denoland/deno/{tag}/std/fs/read_json.ts
Run Code Online (Sandbox Code Playgroud)
因此,您可以将以下内容用于您的代码段:
import { readJson } from 'https://raw.githubusercontent.com/denoland/deno/v1.0.0-rc2/std/fs/read_json.ts'
import { writeJson } from 'https://raw.githubusercontent.com/denoland/deno/v1.0.0-rc2/std/fs/write_json.ts'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
702 次 |
| 最近记录: |