diff --git a/packages/gatsby/src/utils/cache.ts b/packages/gatsby/src/utils/cache.ts index 5a1187138fc0c..2e1fac90295fe 100644 --- a/packages/gatsby/src/utils/cache.ts +++ b/packages/gatsby/src/utils/cache.ts @@ -53,8 +53,11 @@ export default class Cache { get(key): Promise { return new Promise(resolve => { - // eslint-disable-next-line no-unused-expressions - this.cache?.get(key, (err, res) => { + if (!this.cache) { + resolve(undefined) + return + } + this.cache.get(key, (err, res) => { resolve(err ? undefined : res) }) }) @@ -66,8 +69,11 @@ export default class Cache { args: CachingConfig = { ttl: TTL } ): Promise { return new Promise(resolve => { - // eslint-disable-next-line no-unused-expressions - this.cache?.set(key, value, args, err => { + if (!this.cache) { + resolve(undefined) + return + } + this.cache.set(key, value, args, err => { resolve(err ? undefined : value) }) })