KaKi87
KaKi87โ€ข14mo ago

Read permission & NPM imports

Hello, I'm using --allow-read=. to allow a script to read files in the current directory. The script also use NPM imports, because of which it also asks to read /home/{username}/.cache/deno. Can I not need to explicitly allow this path, especially since it will differ depending on operating systems and installation modes ? Thanks
10 Replies
Deno AI Helper
Deno AI Helperโ€ข14mo ago
Hello! ๐Ÿฆ• The Deno cache directory is used to store the downloaded dependencies, including npm packages. When you import an npm package, Deno fetches it and stores it in this cache directory. Therefore, the script needs read access to this directory to be able to load the dependencies. However, you don't need to explicitly allow read access to the Deno cache directory. When you grant the --allow-read permission, it only restricts access to the file system outside of the Deno internal directories. The Deno cache directory is considered an internal directory, and Deno scripts have automatic access to it. So, using --allow-read=. should be sufficient for your use case. It will allow the script to read files in the current directory and also load npm packages from the Deno cache directory. I hope this helps! Let me know if you have any other questions.
leigh
leighโ€ข14mo ago
Are you loading an npm import dynamically? Could that be why it's asking for permission?
KaKi87
KaKi87โ€ข14mo ago
Nope, here are my imports :
import { join as joinPath } from 'https://deno.land/std@0.201.0/path/mod.ts';

import createFastify from 'npm:fastify@4.22.2';
import fastifyStatic from 'npm:@fastify/static@6.11.0';
import fastifyView from 'npm:@fastify/view@8.0.0';
import Handlebars from 'npm:handlebars@4.7.8';
import { join as joinPath } from 'https://deno.land/std@0.201.0/path/mod.ts';

import createFastify from 'npm:fastify@4.22.2';
import fastifyStatic from 'npm:@fastify/static@6.11.0';
import fastifyView from 'npm:@fastify/view@8.0.0';
import Handlebars from 'npm:handlebars@4.7.8';
Here's my command :
deno run --allow-read=. --allow-env --allow-sys=hostname --allow-net ./main.js
deno run --allow-read=. --allow-env --allow-sys=hostname --allow-net ./main.js
And here's the output :
โ”Œ :warning: Deno requests read access to "/home/kaki/.cache/deno/npm/node_modules".
โ”œ Run again with --allow-read to bypass this prompt.
โ”” Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all read permissions) >
โ”Œ :warning: Deno requests read access to "/home/kaki/.cache/deno/npm/node_modules".
โ”œ Run again with --allow-read to bypass this prompt.
โ”” Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all read permissions) >
@leighmcculloch ๐Ÿ™
leigh
leighโ€ข14mo ago
What version of Deno?
KaKi87
KaKi87โ€ข14mo ago
1.36.4
Leokuma
Leokumaโ€ข14mo ago
If Deno is complaining because of a require() call, I think that shouldn't happen. But if one of your deps is opening a file dynamically, then I'm not sure what the behavior should be I think you can use deno vendor to put all deps in the current folder. Not sure if it works for node modules, though
KaKi87
KaKi87โ€ข14mo ago
if one of your deps is opening a file dynamically, then I'm not sure what the behavior should be
I see. How could I know where exactly does the permission request comes from ?
Leokuma
Leokumaโ€ข14mo ago
I don't know ๐Ÿ˜…
KaKi87
KaKi87โ€ข14mo ago
@leighmcculloch ๐Ÿ™
leigh
leighโ€ข14mo ago
I randomly started experiencing the same issue. Opened issue: https://github.com/denoland/deno/issues/20484
GitHub
Importing npm dep requires --allow-read of node_modules ยท Issue #20...
What version of Deno are you using? โฏ deno --version deno 1.36.4 (release, aarch64-apple-darwin) v8 11.6.189.12 typescript 5.1.6 What did you do? Created a basic project that imports an npm: depend...