..
..17mo ago

Confused by deno vendor-related behaviors

I created a main.ts containing this code:
import * as thrift from "npm:thrift";
let connection = thrift.createConnection("localhost", 9160);
import * as thrift from "npm:thrift";
let connection = thrift.createConnection("localhost", 9160);
I ran this command:
noct@ubuntu:~/host_home/projects/godot_engine_4/example/game_mods$ deno vendor --node-modules-dir=true main.ts
Vendored 0 modules into vendor/ directory.
noct@ubuntu:~/host_home/projects/godot_engine_4/example/game_mods$ deno vendor --node-modules-dir=true main.ts
Vendored 0 modules into vendor/ directory.
No vendor/ directory was created, but it generated the following:
noct@ubuntu:~/host_home/projects/godot_engine_4/example/game_mods$ ls -l node_modules/
total 4
lrwxrwxrwx 1 noct users 115 Aug 15 01:37 thrift -> /run/host/xhome/noct/projects/godot_engine_4/example/game_mods/node_modules/.deno/thrift@0.18.1/node_modules/thrift
noct@ubuntu:~/host_home/projects/godot_engine_4/example/game_mods$ ls -l node_modules/
total 4
lrwxrwxrwx 1 noct users 115 Aug 15 01:37 thrift -> /run/host/xhome/noct/projects/godot_engine_4/example/game_mods/node_modules/.deno/thrift@0.18.1/node_modules/thrift
I created a deno.json:
{
"nodeModulesDir": true,
}
{
"nodeModulesDir": true,
}
I then tried to run main.ts:
noct@ubuntu:~/host_home/projects/godot_engine_4/example/game_mods$ deno run --no-remote main.ts
:white_check_mark: Granted read access to "/run/host/xhome/noct/projects/godot_engine_4/example/node_modules".
:white_check_mark: Granted read access to "/run/host/xhome/noct/projects/godot_engine_4/node_modules".
:white_check_mark: Granted read access to "/run/host/xhome/noct/projects/node_modules".
:white_check_mark: Granted read access to "/run/host/xhome/noct/node_modules".
:white_check_mark: Granted read access to "/run/host/xhome/node_modules".
:white_check_mark: Granted read access to "/run/host/node_modules".
:white_check_mark: Granted read access to "/run/node_modules".
:white_check_mark: Granted read access to "/node_modules".
error: Uncaught TypeError: Cannot read properties of undefined (reading 'connect_timeout')
at Module.exports.createConnection (file:///run/host/xhome/noct/projects/godot_engine_4/example/game_mods/node_modules/.deno/thrift@0.18.1/node_modules/thrift/lib/nodejs/lib/thrift/connection.js:269:22)
at file:///run/host/xhome/noct/projects/godot_engine_4/example/game_mods/main.ts:2:25
noct@ubuntu:~/host_home/projects/godot_engine_4/example/game_mods$ deno run --no-remote main.ts
:white_check_mark: Granted read access to "/run/host/xhome/noct/projects/godot_engine_4/example/node_modules".
:white_check_mark: Granted read access to "/run/host/xhome/noct/projects/godot_engine_4/node_modules".
:white_check_mark: Granted read access to "/run/host/xhome/noct/projects/node_modules".
:white_check_mark: Granted read access to "/run/host/xhome/noct/node_modules".
:white_check_mark: Granted read access to "/run/host/xhome/node_modules".
:white_check_mark: Granted read access to "/run/host/node_modules".
:white_check_mark: Granted read access to "/run/node_modules".
:white_check_mark: Granted read access to "/node_modules".
error: Uncaught TypeError: Cannot read properties of undefined (reading 'connect_timeout')
at Module.exports.createConnection (file:///run/host/xhome/noct/projects/godot_engine_4/example/game_mods/node_modules/.deno/thrift@0.18.1/node_modules/thrift/lib/nodejs/lib/thrift/connection.js:269:22)
at file:///run/host/xhome/noct/projects/godot_engine_4/example/game_mods/main.ts:2:25
1 Reply
..
..OP17mo ago
I am confused on two points: 1 - Why the error occurs, (but that may be my test code being bad). 2 - Why does deno try to access node_modules in all these directories? I only want it to access (and only try to access) the one in the current directory. I guess while I am posing questions, I'll also ask if this is the correct/best way to achieve the goal of being able to include needed modules without downloading them remotely? Ok, I think I found my answer to 1 - The example I was following left off the options parameter for the createConnection function. I still have no idea about 2, though. Ok, this behavior of searching all the directories is apparently modeled after node's module resolution algorithm, so it is not a bug. Using deno run --deny-read=../ seems to stop the behavior, though. I'm not sure why --deny-read=../ doesn't prevent reading ./, but it doesn't seem to do so, so this works to solve this problem for now.