Birk Skyum
Birk Skyum3mo ago

canary `deno install` - can't find npm modules

deno 2.0.0-rc.1+7bfcb4d I'm having a deno.json like this
{
"tasks": {
"test": "vitest"
},
"imports": {
"vitest": "npm:vitest@^2.0.5"
}
}
{
"tasks": {
"test": "vitest"
},
"imports": {
"vitest": "npm:vitest@^2.0.5"
}
}
I run deno install I have a test like this:
import { expect, test } from "vitest"; // <- "Cannot find module 'vitest' or its corresponding type declarations.ts(2307)
function sum(a, b) {
return a + b
}
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3)
})
import { expect, test } from "vitest"; // <- "Cannot find module 'vitest' or its corresponding type declarations.ts(2307)
function sum(a, b) {
return a + b
}
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3)
})
Why can the type declarations not be found? deno install doesn't seem to make a node_modules folder by default - is that necessary for this this type to be found, or can the import mapping work? I also have the vitest.config.ts like this:
import {defineConfig} from "vitest/config";

export default defineConfig({
test: {
include: ['sum.test.ts']
}
})
import {defineConfig} from "vitest/config";

export default defineConfig({
test: {
include: ['sum.test.ts']
}
})
and when I run the task deno task test I get an error that "vitest/config" also can't be found:
deno task test
Task test vitest
[ERROR] Unterminated string literal

vitest.config.ts:1:366:
1 │ ...e:///Users/admin/repos/deno-kitchensink/vitest-demo/vitest.config.ts";import {defineConfig} from "vitest/config';
╵ ^

failed to load config from /Users/admin/repos/deno-kitchensink/vitest-demo/vitest.config.ts
deno task test
Task test vitest
[ERROR] Unterminated string literal

vitest.config.ts:1:366:
1 │ ...e:///Users/admin/repos/deno-kitchensink/vitest-demo/vitest.config.ts";import {defineConfig} from "vitest/config';
╵ ^

failed to load config from /Users/admin/repos/deno-kitchensink/vitest-demo/vitest.config.ts
5 Replies
marvinh.
marvinh.3mo ago
You're having a syntax error in your vitest.config.ts file. A string or import specifier needs to start and end with the same quotation style. If it starts with double quotes it needs to end with double quotes.
- import {defineConfig} from "vitest/config';
+ import {defineConfig} from "vitest/config";

export default defineConfig({
test: {
include: ['sum.test.ts']
}
})
- import {defineConfig} from "vitest/config';
+ import {defineConfig} from "vitest/config";

export default defineConfig({
test: {
include: ['sum.test.ts']
}
})
Birk Skyum
Birk SkyumOP3mo ago
Oh, right! So now I get "Error: Cannot find module 'vitest/config'" Should I setup-up import mapping for that as well next to the one for "vitest"
Birk Skyum
Birk SkyumOP3mo ago
the types aren't picked up
No description
marvinh.
marvinh.3mo ago
not sure about the other errors. Just saw the typo in your code before going to bed. Might be worth filing an issue on GitHub for this
Birk Skyum
Birk SkyumOP3mo ago
And thank you for that - I'd totally missed that Aha! Turns out adding the ""nodeModulesDir": "auto"," in the deno.json, and running deno install does wonders here.