typescript - 未捕获的语法错误:请求的模块“https://deno.land/std/uuid/mod.ts”未提供名为“v4”的导出
问题描述
我第一次尝试在个人项目中使用 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
解决方案
尝试为模块使用版本化 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)
推荐阅读
- prefect - 如何永久设置本地 Prefect 配置文件?
- curl - 如何解决清漆清除器在 1000 毫秒后超时,收到 0 个字节中的 0 个字节并出现 cURL 错误 28
- python - 遍历 Pandas Dataframe 中定义的日期时间索引范围
- python - Python - 添加约束时优化“凸”的非凸函数
- laravel - Laravel 计划无法在 Cronjob Cpanel 中工作
- python - 有没有办法在使用 Python 解析 PDF 文件时识别被划掉的单词?
- amazon-web-services - 防止意外删除 AWS S3 存储桶
- python - 在 Jupyter 中运行以下代码时出现错误(numpy.ndarray' 对象不可调用)
- database - Splunk:对多个数据源执行相同的查询
- javascript - 如何从javascript获取列的所有行的总和?