gpt4 book ai didi

Deno 属性 'utime' 在类型 'typeof Deno' 上不存在。 await Deno.utime(dest, statInfo.atime, statInfo.mtime);

转载 作者:行者123 更新时间:2023-12-04 02:36:11 33 4
gpt4 key购买 nike

我正在尝试使用标准的 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);

我的 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

最佳答案

Deno.utimebeen marked unstable ,这就是为什么你应该使用 --unstable 标志

还有一个 Unresolved 问题:Property 'utime' does not exist on type 'typeof Deno'对于这个错误。

目前有多个APIs which are behind the unstable flag .

As of Deno 1.0.0, the Deno namespace APIs are stable. That means that we will strive to make code working under 1.0.0 continue to work in future versions.

However, not all of Deno's features are ready for production yet. Features which are not ready because they are still in draft phase are locked behind the --unstable command line flag.


使用 Deno.utime 的文件是 copy.tsensure_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'

关于Deno 属性 'utime' 在类型 'typeof Deno' 上不存在。 await Deno.utime(dest, statInfo.atime, statInfo.mtime);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61719244/

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