TangJieHao
TangJieHao4mo ago

Deno + Puppeteer causing compiler issues.

I get an error that document cannot be found. It's asking if I am trying to change the library. but when running deno run -allow-all --unstable it works error: TS2584 [ERROR]: Cannot find name 'document'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'. const rows = document.querySelectorAll(".review-history-table tbody tr"); ~~~~
2 Replies
Deno AI Helper
Deno AI Helper4mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the error message you've provided, it seems like the TypeScript compiler is unable to recognize the document object. This is likely because the document object is part of the DOM API, which is available in web browsers but not by default in the Deno runtime environment. The error suggests adjusting the lib compiler option to include 'dom'. This can be done in a tsconfig.json file, which you would reference when running your Deno command. Here's an example of how you might adjust your tsconfig.json:
{
"compilerOptions": {
"lib": ["dom", "esnext"]
}
}
{
"compilerOptions": {
"lib": ["dom", "esnext"]
}
}
And then you would run Deno with the --config flag pointing to your tsconfig.json file:
deno run --allow-all --unstable --config tsconfig.json your_script.ts
deno run --allow-all --unstable --config tsconfig.json your_script.ts
Please note that this advice is not based on the Deno documentation, and you should double-check the accuracy of this advice. If you continue to experience issues, you may want to explore the community resources or the issue tracker for the Deno project to see if others have encountered and resolved similar problems.
ioB
ioB4mo ago
you can add
/// <reference lib="dom" />
/// <reference lib="dom" />
anywhere in the file :) (I recommend putting it at the top)