briandoesdev
briandoesdev

Reputation: 141

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

I am attempting to use Deno for the first time on a personal project but have been running into this issue that I can't seem to solve. Whenever I add a new import statement I get the same error, something along the lines of:

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

Whenever you look at the module though, you can see 'v4' is being exported:

// 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 };

In my code this is my import statement:

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

And that is how this article is importing it as well https://medium.com/deno-the-complete-reference/all-about-uuids-in-deno-b8d04ce96535

Does anyone know what may be happening here? I have done a deno cache --reload and that doesn't seem to fix my issue. Also, I am using WebStorm with the Deno plugin if that makes a difference.

Thank you!

EDIT: Also, I am running deno with the following arguments: deno run --allow-all --unstable

Upvotes: 1

Views: 757

Answers (1)

jsejcksn
jsejcksn

Reputation: 33881

Try using a versioned URL for the module. The versioned modules at deno.land/std are advertised as being immutable, so you should never have a cache issue with a versioned URL for a std module.

Unversioned:
https://deno.land/std/uuid/mod.ts

Versioned:
https://deno.land/[email protected]/uuid/mod.ts

Here's an example in a test file:

so-69918417.test.ts:

import {assert} from 'https://deno.land/[email protected]/testing/asserts.ts';
import {v4 as uuid} from 'https://deno.land/[email protected]/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)

Upvotes: 0

Related Questions