【问题标题】:Uncaught SyntaxError: The requested module 'https://deno.land/std/uuid/mod.ts' does not provide an export named 'v4'未捕获的语法错误:请求的模块“https://deno.land/std/uuid/mod.ts”未提供名为“v4”的导出
【发布时间】:2021-12-23 08:32:15
【问题描述】:

我第一次尝试在个人项目中使用 Deno,但遇到了这个我似乎无法解决的问题。每当我添加一个新的导入语句时,我都会遇到同样的错误,类似于:

error: Uncaught SyntaxError: The requested module 'https://deno.land/std/uuid/mod.ts' does not provide an export named 'v4'

不过,无论何时查看模块,您都可以看到正在导出“v4”:

// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.

// Based on https://github.com/kelektiv/node-uuid -> https://www.ietf.org/rfc/rfc4122.txt
// Supporting Support for RFC4122 version 1, 4, and 5 UUIDs

import * as v1 from "./v1.ts";
import * as v4 from "./v4.ts";
import * as v5 from "./v5.ts";

export const NIL_UUID = "00000000-0000-0000-0000-000000000000";

/**
 * Check if the passed UUID is the nil UUID.
 *
 * ```js
 * import { isNil } from "./mod.ts";
 *
 * isNil("00000000-0000-0000-0000-000000000000") // true
 * isNil(crypto.randomUUID()) // false
 * ```
 */
export function isNil(id: string): boolean {
  return id === NIL_UUID;
}

export { v1, v4, v5 };

在我的代码中,这是我的导入语句:

import { v4 } from "https://deno.land/std/uuid/mod.ts";

这也是本文导入它的方式https://medium.com/deno-the-complete-reference/all-about-uuids-in-deno-b8d04ce96535

有人知道这里会发生什么吗?我已经完成了deno cache --reload,但这似乎并不能解决我的问题。另外,如果有影响的话,我正在使用带有 Deno 插件的 WebStorm。

谢谢!

编辑:另外,我正在使用以下参数运行 deno: deno run --allow-all --unstable

【问题讨论】:

  • 尝试像这样导入它:import {v4 as uuidv4}
  • @InsalataCondita 当我使用导入 import {v4 as uuidv4} from "https://deno.land/std/uuid/mod.ts"; 时出现以下错误:error: Uncaught SyntaxError: The requested module 'https://deno.land/std/uuid/mod.ts' does not provide an export named 'v4' import {v4 as uuidv4} from "https://deno.land/std/uuid/mod.ts";
  • 您是否缓存了该库的旧版本?我刚刚尝试了标准库的 0.114.0 版本,并且导入按预期工作

标签: typescript import deno


【解决方案1】:

尝试使用模块的版本化 URL。 deno.land/std 中的版本化模块被宣传为不可变的,因此您永远不会遇到 std 模块的版本化 URL 的缓存问题。

未版本化:
https://deno.land/std/uuid/mod.ts

版本化:
https://deno.land/std@0.114.0/uuid/mod.ts

这是一个测试文件中的示例:

so-69918417.test.ts:

import {assert} from 'https://deno.land/std@0.114.0/testing/asserts.ts';
import {v4 as uuid} from 'https://deno.land/std@0.114.0/uuid/mod.ts';

Deno.test('Generates valid UUID', () => {
  let id = uuid.generate();
  assert(uuid.validate(id));

  // However, the `generate` method on v4 is just a proxy to this:
  id = crypto.randomUUID();
  assert(uuid.validate(id));
});
PS> deno test .\so-69918417.test.ts
Check file:///C:/Users/deno/so-69918417.test.ts
running 1 test from file:///C:/Users/deno/so-69918417.test.ts
test Generates valid UUID ... ok (15ms)

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (50ms)

【讨论】:

    猜你喜欢
    • 2022-01-06
    • 2021-12-27
    • 2022-01-13
    • 1970-01-01
    • 2020-10-13
    • 2023-01-27
    • 2022-08-10
    • 2022-06-19
    • 2022-01-18
    相关资源
    最近更新 更多