UnknownError
UnknownError•2w ago

Cannot find CanvasRenderingContext2D

I am trying to use deno for a web target. Just to transpile all the TypeScript source code into a single JavaScript target. I am compiling with deno bundle --watch src/index.ts package.js --unstable-sloppy-imports. With a fairly simple tsconfig.json:
{
"compilerOptions": {
"target": "ESNext",
"lib": [
"DOM",
"ESNext"
],
"module": "ESNext",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
{
"compilerOptions": {
"target": "ESNext",
"lib": [
"DOM",
"ESNext"
],
"module": "ESNext",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
This is the first time I am using deno, so I'm not really sure if deno requires that I bring in some type hints for a native web target or to adjust the tsconfig.json (or if deno even uses this file) or add in additional cli commands to specify that this will be a web target. But deno currently cannot find CanvasRenderingContext2D.
10 Replies
bartlomieju
bartlomieju•2w ago
@crowlKats can you answer that?
crowlKats
crowlKats•2w ago
i believe lib names need to be lowercase?
UnknownError
UnknownError•2w ago
I changed the tsconfig to:
{
"compilerOptions": {
"target": "esnext",
"lib": [
"dom",
"esnext"
],
"module": "esnext",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
{
"compilerOptions": {
"target": "esnext",
"lib": [
"dom",
"esnext"
],
"module": "esnext",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
Unfortunately, the same issue. I believe this is the lib names you were referring to. Is there a specific lib I need to specify to enable canvas based features? I am using es2022 Set, and deno does not complain about that. Nor does deno complain about the use of window and other dom commands.
bartlomieju
bartlomieju•2w ago
Hm, it appears it's indeed present in the lib.deno.d.ts that Deno ships with Which version of Deno are you on?
UnknownError
UnknownError•2w ago
deno 1.46.3 (stable, release, x86_64-unknown-linux-gnu)
v8 12.9.202.5-rusty
typescript 5.5.2
deno 1.46.3 (stable, release, x86_64-unknown-linux-gnu)
v8 12.9.202.5-rusty
typescript 5.5.2
bartlomieju
bartlomieju•2w ago
Can you paste your input file and the full output from the terminal
bartlomieju
bartlomieju•2w ago
Oh I know what the problem is 😄 Deno doesn't recognize tsconfig.json file You need to pass it explicitly with --config=tsconfig.json Or move these options into deno.json
UnknownError
UnknownError•2w ago
Thanks. Moved the file to deno.json. All those errors are fixed. Thanks for your help!
bartlomieju
bartlomieju•2w ago
Great!