question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:17

github_iconTop GitHub Comments

2reactions
chronarkcommented, Jun 14, 2022

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?

1reaction
chronarkcommented, Jul 30, 2022

thank you so much. I’ll check it out

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Dynamically Import ECMAScript Modules
The imported module — the one which exports export const func = () => {} and is being imported. The importing module uses...
Read more >
Issues · upstash/upstash-redis - GitHub
3. @upstash/redis import in file causing module to be imported dynamically. #109 opened on Jun 13 by cathykc · @chronark.
Read more >
ES2020: `import()` – dynamically importing ES modules - 2ality
The proposal enables dynamic module imports #. The proposed operator for loading modules dynamically works as follows: const moduleSpecifier = ' ...
Read more >
Dynamic Module Imports - Web Dev Simplified Blog
By using dynamic module imports you can speed up your applications ... JavaScript across multiple files and import them only when needed.
Read more >
How to use Dynamic Imports for Modules - JavaScript Tutorial
In today's video I'll be showing you how to use Dynamic Imports for your modules in JavaScript - this allows you to dynamically...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found