Reputation: 6503
when run an application using deno run app.ts
command and its give an error: Uncaught PermissionDenied
error: Uncaught PermissionDenied: access to environment variables, run again with the --allow-env flag
at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
at Object.sendSync ($deno$/ops/dispatch_json.ts:72:10)
at Object.toObject ($deno$/ops/os.ts:33:12)
at file:///opt//deno/app.ts:5:22
Upvotes: 3
Views: 2341
Reputation: 6503
This type of issue we need to set a flag when run application
diffrent kind of permmistions
--allow-env
Allow environment access
--allow-hrtime
Allow high resolution time measurement
--allow-net=<allow-net>
Allow network access
--allow-plugin
Allow loading plugins
--allow-read=<allow-read>
Allow file system read access
--allow-run
Allow running subprocesses
--allow-write=<allow-write>
Allow file system write access
deno run -allow-all app.ts
Example
//Give an environment permission
deno run --allow-env app.ts
//Give an all permission
deno run -allow-all app.ts
OR
deno run -A app.ts
Ref link: https://stackoverflow.com/a/61878925/9077019
Upvotes: 5
Reputation: 11622
In your console log, the error caused by trying to access environment variables, in Deno you have to provide/grant the permission flags to be able to access the environment variables:
If you are reading envirnoment variables directly from the terminal:
> TEST=123 deno --allow-env app.ts
If you are reading envirnoment variables from .env file:
> TEST=123 deno --allow-env --allow-read app.ts
NOTE: always priorities least privilege principle and don't grant all permissions arbitrary to the app.
Upvotes: 1