【问题标题】:Deno Property 'utime' does not exist on type 'typeof Deno'. await Deno.utime(dest, statInfo.atime, statInfo.mtime);Deno 属性 'utime' 在类型 'typeof Deno' 上不存在。等待 Deno.utime(dest, statInfo.atime, statInfo.mtime);
【发布时间】:2020-08-26 09:02:32
【问题描述】:

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


    【解决方案1】:

    Deno.utimebeen marked unstable,这就是你应该使用--unstable 标志的原因

    还有一个未解决的问题:Property 'utime' does not exist on type 'typeof Deno' 表示此错误。

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

    从 Deno 1.0.0 开始,Deno 命名空间 API 是稳定的。这意味着 我们将努力使在 1.0.0 下工作的代码继续工作 未来的版本。

    但是,并非 Deno 的所有功能都已准备好投入生产。 由于仍处于草稿阶段而未准备就绪的功能是 锁定在 --unstable 命令行标志后面。


    使用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
    

    因此,您可以将以下内容用于您的 sn-p:

    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 还处于起步阶段,所以很多变化正在进行中,还有多种不稳定的方法。
    • 谢谢你,我明白了。为 Deno 感到非常兴奋! github.com/denoland/deno/blob/master/docs/runtime/stability.md
    • 我也是 :)。我会将该链接添加到答案中以帮助其他用户!
    猜你喜欢
    • 2020-09-19
    • 2020-12-02
    • 1970-01-01
    • 2021-01-09
    • 2021-07-16
    • 1970-01-01
    • 2020-10-04
    • 2020-08-19
    • 2017-11-06
    相关资源
    最近更新 更多