Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug dependencies in deno

Node + NPM install dependencies in node_modules, so if I want to debug a dependency, I can just go to node_modules/some-pkg/some-file.js and add debugger statements, console-logs, and the likes.

In Deno, things get trickier, because dependencies are abstracted from the user - it's not plain local JS files anymore! For example, If I have the following code:

// main.js
import oaClient from 'https://cdn.pika.dev/oa-client';
const { createClient } = oaClient;
createClient();

It'll output the stacktrace:

nino@hp:~/learning/deno(master)$ deno run main.js 
error: Uncaught TypeError: Cannot read property 'paths' of undefined
  for (var path in specs.paths) {
                         ^
    at _default (https://cdn.pika.dev/-/[email protected]/dist=es2019/oa-client.js:428:26)
    at file:///home/nino/learning/deno/main.js:3:1

and although I can read the code online at https://cdn.pika.dev/-/[email protected]/dist=es2019/oa-client.js, I can't insert console logs or debugger statements.

Thanks to deno info <the URL above> I can get the local path of the cached copy of the dependency, but I don't think that editing files in ~/.cache/deno is the right way.

So, what's the Deno way to debug dependencies?

like image 989
Nino Filiu Avatar asked Oct 25 '25 21:10

Nino Filiu


1 Answers

You can try deno debugger


An alternative to modifying the global cached dependencies, that will affect all your projects, is to download the package inside your project directory using $DENO_DIR environment variable.

DENO_DIR=$PWD/modules deno run main.js

Now you can modify the contents inside $DENO_DIR/deps without affecting other projects, after you're done you can use: --reload to download all dependencies again.

To find out the file name, just do:

DENO_DIR=$PWD/modules deno info {package-url}
like image 147
Marcos Casagrande Avatar answered Oct 28 '25 11:10

Marcos Casagrande



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!