deno icon indicating copy to clipboard operation
deno copied to clipboard

[Bug]PermissionDenied: Reading package.json is not allowed when using npm:[email protected]

Open char8x opened this issue 3 years ago • 1 comments

Problem

Output PermissionDenied when running

deno run --unstable --allow-env --allow-read npm:[email protected] test.js

Simplest Reproduction

Project files like this

test.js

import assert from "assert";
describe("Array", function () {
  describe("#indexOf()", function () {
    it("should return -1 when the value is not present", function () {
      assert.equal([1, 2, 3].indexOf(4), -1);
    });
  });
});

package.json

{
  "type": "module"
}

file permission

drwxr-xr-x   .
drwxr-xr-x   ..
-rw-r--r--   package.json
-rw-r--r--   test.js

Error Output

PermissionDenied: Reading .../mocha-example/package.json is not allowed
    at Object.Module._extensions..js (deno:ext/node/02_require.js:731:28)
    at Module.load (deno:ext/node/02_require.js:630:34)
    at Function.Module._load (deno:ext/node/02_require.js:487:14)
    at Module.require (deno:ext/node/02_require.js:652:21)
    at require (deno:ext/node/02_require.js:782:18)
    ...

Extra Info

Deno: v1.25.2 macOS: 11.6.8

char8x avatar Sep 10 '22 08:09 char8x

It appears it only allows reading if it's in the deno_dir node modules. I'm not sure exactly how this should work

brenelz avatar Sep 11 '22 15:09 brenelz

i have similar issue with trying to get eslint to work FWIW ("cant" read package.json or .eslintrc.js)

traceypooh avatar Oct 25 '22 04:10 traceypooh

Can still reproduce in the latest canary. The npm code needs to take user permissions into account instead of being restricted to the cache or node_modules directory.

dsherret avatar Dec 20 '22 22:12 dsherret

https://github.com/denoland/deno/pull/17134 will be a stepping stone to fix this problem.

bartlomieju avatar Dec 20 '22 22:12 bartlomieju

Does anyone have a work around?

arjunyel avatar Jan 07 '23 15:01 arjunyel