upstash-redis: @upstash/redis import in file causing module to be imported dynamically

This is an issue as of 1.3.2-alpha.0 - fine for 1.3.0 (the version we’ve now pinned our application to).

Platform: Next.js 12.0.7

We have a very simple file (redis.ts):

import { Redis } from "@upstash/redis";
const redis = Redis.fromEnv();
export default redis;

We then import this in another file (import redis from "./redis";) - The redis object is now a promise that needs to be awaited before we can access the exported properties. This is leading us to believe that Next is interpreting something upstream as needing to be dynamically imported.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

Hey @cathykc, thank you for reporting this.

We recently found something similar in nextjs I believe. For some reason it didn’t load environment variables properly, when creating such a utility redis.ts file. The fix was to just not do that and create a new Redis.fromEnv() instance instead of importing from the utility file, which doesn’t cause any issues, as the sdk is completely stateless.

However it’s not a perfect solution either. I will dig some more.

In the meantime, can you try upgrading to v1.6.0 and see if this behavior still exists?

thank you so much. I’ll check it out

@Ali-Hussein-dev yeah please try.

Hmmm, it might be caused by getServerSideProps. I’ll play around with it, thanks for sharing.