Reputation: 4589
Using Deno 2.0.6 on Windows 11
I'm using civet 0.8.7 to produce *.js files and civet doesn't yet support things like:
import {assert} from 'jsr:@std/assert'
import {globSync} from 'npm:glob'
NOTE: this is NOT an issue with civet itself - it's regarding imports in deno
i.e. the jsr: and npm: isn't allowed. I thought that the solution would be to add these to my deno.jsonc imports key:
"@std/assert": "jsr:@std/assert@^1.0.8",
"glob": "npm:glob@^11.0.0",
However, when I try to import a file containing:
import {assert} from '@std/assert'
import {globSync} from 'glob'
I get the error message:
error: Relative import path "@std/streams" not prefixed with / or ./ or ../
hint: If you want to use a JSR or npm package, try running `deno add jsr:@std/streams` or `deno add npm:@std/streams`
at file:///C:/Users/johnd/vllu/src/lib/llutils.js:7:30
I thought that with the entries for "@std/assert" and "glob" in my deno.jsonc file (inside the "imports" key), deno would realize that these are NOT relative imports?
FYI, I did try running 'deno add jsr:@std/streams' as suggested. It runs fine, but I still get the error message above, so it didn't help.
FYI, here is my entire deno.jsonc
file:
{
// --- Comments and trailing commas allowed!
"tasks": {
"build:llutils": "civet --js -o .js --inline-map -c src/lib/llutils.civet",
"build:compile": "civet --js -o .js --inline-map -c src/bin/compile.civet",
"install:compile": "deno install -fgA src/bin/compile.js",
"build": "deno task build:llutils && deno task build:compile && deno task install:compile && compile",
},
"imports": {
"@std/assert": "jsr:@std/assert@^1.0.8",
"@std/async": "jsr:@std/async@^1.0.9",
"@std/cli": "jsr:@std/cli@^1.0.6",
"@std/path": "jsr:@std/path@^1.0.8",
"@std/streams": "jsr:@std/streams@^1.0.8",
"glob": "npm:glob@^11.0.0",
},
}
Upvotes: 0
Views: 265
Reputation: 693
If you're using the VS Code test runner, then the following will give you the error: "Relative import path "@std/assert" not prefixed with / or ./ or ../ etc."
import { assertEquals } from "@std/assert";
However, specifying the full path to your import will make it work.
import { assertEquals } from "jsr:@std/assert@1";
If you take a quick look at the default deno.json file, you'll notice that the import for @std/assert is being aliased from the full import jsr:std/assert@1
{
"tasks": {
"dev": "deno run --watch main.ts"
},
"imports": {
"@std/assert": "jsr:@std/assert@1"
}
}
It seems the VS Code test runner does not take the deno.json file into account. If instead you run the test with deno test
it should work either way.
source: https://docs.deno.com/runtime/fundamentals/modules/#importing-third-party-modules-and-libraries
Upvotes: 1
Reputation: 1
I had this issue too. Today I upgraded deno and found out I had two different installations.
Default Terminal: /Users/userName/.deno/bin/deno (version 2.1.3)
Vscode using homebrew: /opt/homebrew/bin/deno (version 1.44.4)
I know you use windows. But for mac I needed to brew uninstall deno and then the correct version was available in vscode.
Upvotes: 0