/errors/deno/notcapable-requires-read-access
Deno: NotCapable: Requires read access to "data.txt", run again with the --allow-read flag
- tool
- Deno
- exit code
- 1
- versions
- Deno 2.x
- os
- any
NotCapable: Requires read access to "data.txt", run again with the --allow-read flag means the script tried to read a file and Deno's permission system blocked it. Deno runs code without file, network, environment or subprocess access unless you grant it. Add --allow-read to the deno run command, preferably scoped to the path the script needs: deno run --allow-read=data.txt main.ts.
Reproduce it
echo "hello" > data.txt
echo 'console.log(Deno.readTextFileSync("data.txt"));' > main.ts
npx --yes deno@2 run main.ts 2>&1 | head -1
exit "${PIPESTATUS[0]}"Output · exit 1
error: Uncaught (in promise) NotCapable: Requires read access to "data.txt", run again with the --allow-read flag
Only the first line is kept; Deno also prints the source line and a stack trace. Without a terminal (CI, scripts, this run) Deno does not prompt and the call fails at once. In an interactive terminal Deno first asks Allow? and the error appears only if you answer no.
Fix
echo "hello" > data.txt
echo 'console.log(Deno.readTextFileSync("data.txt"));' > main.ts
npx --yes deno@2 run --allow-read=data.txt main.tsOutput
hello
The same message exists for every permission, with the matching flag in the text:
| Message starts with | Flag to add |
|---|---|
| Requires read access to | --allow-read[=PATH] |
| Requires write access to | --allow-write[=PATH] |
| Requires net access to | --allow-net[=HOST] |
| Requires env access to | --allow-env[=NAME] |
| Requires run access to | --allow-run[=PROGRAM] |
In Deno 1.x the same failure was reported as PermissionDenied; Deno 2 uses the NotCapable error class, so code that checks instanceof Deno.errors.PermissionDenied must be updated.