Import from "@std/yaml/parse" or "@std/yaml" throwing relative path error.

I'm using the example on this Standard Library page: https://jsr.io/@std/yaml/doc/~/parse
import { parse } from "@std/yaml/parse";
import { assertEquals } from "@std/assert";

const data = parse(`
id: 1
name: Alice
`);

assertEquals(data, { id: 1, name: "Alice" });
import { parse } from "@std/yaml/parse";
import { assertEquals } from "@std/assert";

const data = parse(`
id: 1
name: Alice
`);

assertEquals(data, { id: 1, name: "Alice" });
When I run it, I get a relative path error:
$ deno run main.js
error: Relative import path "@std/assert" not prefixed with / or ./ or ../
$ deno run main.js
error: Relative import path "@std/assert" not prefixed with / or ./ or ../
I'd love to use the standard library the right way in the latest Deno version. I'm running Deno 1.46.1 on Ubunut 22.04. Can't tell what I'm doing wrong. I'm copy pasting from the usage example and getting an error I don't know what to do with.
parse - @std/yaml - JSR
@std/yaml on JSR: Parsing and serializing of YAML files
2 Replies
IdeasAndAction
Ah.... You have to add it via deno add @std/yaml first. This is much closer to Node than I have gotten used to so far.
marvinh.
marvinh.3w ago
It sounds like there are no import mappings in your deno.json for these two. Either add these or add the jsr: prefix before the imports.
// deno.json
{
"imports": {
"@std/assert": "jsr:@std/assert@^1.0.3",
"@std/yaml": "jsr:@std/yaml@^1.0.4",
}
}
// deno.json
{
"imports": {
"@std/assert": "jsr:@std/assert@^1.0.3",
"@std/yaml": "jsr:@std/yaml@^1.0.4",
}
}
Or do this as an alternative:
- import { parse } from "@std/yaml/parse";
+ import { parse } from "jsr:@std/yaml/parse";
- import { assertEquals } from "@std/assert";
+ import { assertEquals } from "jsr:@std/assert";
- import { parse } from "@std/yaml/parse";
+ import { parse } from "jsr:@std/yaml/parse";
- import { assertEquals } from "@std/assert";
+ import { assertEquals } from "jsr:@std/assert";