我正在尝试使用标准的deno模块,但是编译器在没有--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);我的deno版本:
deno 1.0.0-rc2
v8 8.4.300
typescript 3.8.3我总是犯同样的错误。它们似乎与缺少的模块有关,但我不确定可能缺少什么。
➜ 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.如果我只导入readJson模块,那么就不会出现错误。
import { readJson } from "https://deno.land/std/fs/read_json.ts";我尝试使用标记构建,但我似乎找不出1.0.0-rc2的标记。我试过https://deno.land/std@0.50.0/fs/mod.ts。
发布于 2020-05-10 22:08:44
Deno.utime有不稳定,这就是为什么要使用--unstable标志的原因。
还有一个悬而未决的问题:针对此错误的属性'utime‘在类型“Deno”中不存在。
目前有多个不稳定标志后面的API。。
从Deno 1.0.0开始,Deno命名空间API是稳定的。这意味着我们将努力使代码在1.0.0下继续工作在未来的版本中。 然而,德诺的所有功能还没有准备好生产。由于仍处于草稿阶段而尚未准备好的特性被锁定在--不稳定的命令行标志后面。
使用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因此,您可以在代码片段中使用以下内容:
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'https://stackoverflow.com/questions/61719244
复制相似问题