TypeError:无法从进程.env中解析URL,UPSTASH_REDIS_REST_URL

pokxtpni  于 7个月前  发布在  Redis
关注(0)|答案(1)|浏览(52)

我在创建一个新的Redis示例时遇到了一个打字脚本的问题。我已经创建了一个.env.local文件,其名称与redis url和token相同

import { Redis } from '@upstash/redis'

export const db: Redis = new Redis({
  url: process.env.UPSTASH_REDIS_REST_URL,
  token: process.env.UPSTASH_REDIS_REST_TOKEN
})

字符串
这是一个错误:

No overload matches this call.
  Overload 2 of 2, '(requesters: Requester): Redis', gave the following error.
  Argument of type '{ url: string | undefined; token: string | undefined; }' is not assignable to     parameter of type 'Requester'.
      Object literal may only specify known properties, and 'url' does not exist in type 'Requester'.ts(2769)
(property) url: string
UPSTASH_REDIS_REST_URL


那我能做什么呢?
我试着在这里和那里查找,但错误仍然存在。

omhiaaxx

omhiaaxx1#

在使用环境变量之前,你需要检查它们不是undefined

if (process.env.UPSTASH_REDIS_REST_URL == null)
  throw new Error('Env UPSTASH_REDIS_REST_URL not set!')
if (process.env.UPSTASH_REDIS_REST_TOKEN == null)
  throw new Error('Env UPSTASH_REDIS_REST_TOKEN not set!')

字符串

相关问题