I tried to initialize a new Redis client using ioredis in my Deno app, but I received an error:

error: Uncaught PermissionDenied: Requires env access, run again with the --allow-env flag.
at Object.toObject (ext:runtime/30_os.js:97:16)
at Object.ownKeys (ext:deno_node/\_process/process.ts:59:41)
at Function.keys (\<anonymous\>)
at Object.\<anonymous\> (file:///deno-dir/npm/registry.npmjs.org/debug/4.3.4/src/node.js:124:30)
at Object.\<anonymous\> (file:///deno-dir/npm/registry.npmjs.org/debug/4.3.4/src/node.js:265:4)
at Module.\_compile (node:module:733:34)
at Object.Module.\_extensions..js (node:module:747:10)
at Module.load (node:module:658:32)
at Function.Module.\_load (node:module:539:12)
at Module.require (node:module:677:19)
Error 1

No exact env variable is specified in the log. Yes, it works when I allow env globally, but for my system, I would like to avoid allowing all env variables.

I'm executing program with:


deno run --allow-env=REDIS_PORT,NODES,PORT,KEYS,NODES,redisPort,redisEndpoint,redisUsername,redisPW,ITERATIONS,BATCH_SIZE,DEBUG,DENOAPP_PORT --allow-net denoapp/app.ts

My singleton redis client implementation:


import { Redis } from "npm:[email protected]";

export class RedisClient {
  private static instance: RedisClient;
  private readonly client: Redis;

private constructor() {
// this client initialization is causing the issue
this.client = new Redis({
  port: 6379,
  host: "172.17.0.1",
  db: 0,
  });
}

public static getInstance(): RedisClient {
  if (!RedisClient.instance) {
    RedisClient.instance = new RedisClient();
  }
  return RedisClient.instance;
  }
}

I tried to add all env used by ioredis plus and also I tried log all the environment variables that Deno accesses using Deno.env.toObject();. I then compared the environment variables with and without the ioredis client, and they were the same.

0

There are 0 best solutions below