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 ?
Thanks10 Replies
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.Are you loading an npm import dynamically? Could that be why it's asking for permission?
Nope, here are my imports :
Here's my command :
And here's the output :
@leighmcculloch ๐
What version of Deno?
1.36.4
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, thoughif one of your deps is opening a file dynamically, then I'm not sure what the behavior should beI see. How could I know where exactly does the permission request comes from ?
I don't know ๐
@leighmcculloch ๐
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...