prehistoric-beach-86927
03/14/2023, 1:12 PMtsc
:
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:
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?"dom"
to compilerOptions.lib
, in tsconfig.json
:
{
"compilerOptions": {
"lib": ["dom"],
}
}