I am trying to test growthbook with NodeJS on serv...
# ask-questions
p
I am trying to test growthbook with NodeJS on server side, but I am getting this error when compiling my TypeScript code with
tsc
:
Copy code
node_modules/@growthbook/growthbook/dist/GrowthBook.d.ts:23:84 - error TS2304: Cannot find name 'SubtleCrypto'.

23     setEncryptedFeatures(encryptedString: string, decryptionKey?: string, subtle?: SubtleCrypto): Promise<void>;
                                                                                      ~~~~~~~~~~~~


Found 1 error in node_modules/@growthbook/growthbook/dist/GrowthBook.d.ts:23
I have created a class to abstract growthbook for the rest of my application like this:
Copy code
import { GrowthBook, setPolyfills } from '@growthbook/growthbook';

setPolyfills({
  // Required when using built-in feature loading and Node 17 or lower
  fetch: require("cross-fetch"),
  // Required when using encrypted feature flags and Node 18 or lower
  SubtleCrypto: require("node:crypto").webcrypto.subtle,
  // Optional, can make feature rollouts faster
  EventSource: require("eventsource"),
})

class XPlat {

  provider: GrowthBook;

  constructor() {
    this.provider = new GrowthBook({
      apiHost: "<https://cdn.growthbook.io>",
      clientKey: "my-key",
      enableDevMode: true,
    });
  }

  isOn(name: string): boolean {
    return this.provider.isOn(name);
  }
}

export const xplat = new XPlat();
I am using
NodeJS
v16.15.1 . I have also tried compiling it with
NodeJs v18
and upgrading
@types/node
to the latest version, but I keep getting the same error. Any idea how to fix this?
Solved it by adding
"dom"
to
compilerOptions.lib
, in
tsconfig.json
:
Copy code
{
  "compilerOptions": {
    "lib": ["dom"],
  }
}