'TypeError: Class extends value undefined is not a constructor or null (svelte redis)
I just got started with svelte and was trying to make an app with redis as the db. I made a typescript file with all the db functions I would need and tried to import it into my svelte components, but when I did that I got the following error
Class extends value undefined is not a constructor or null
TypeError: Class extends value undefined is not a constructor or null
at node_modules/@node-redis/client/dist/lib/client/socket.js (http://localhost:3000/node_modules/.vite/chunk-L35TFNQI.js?v=60c87e0f:6515:46)
at __require (http://localhost:3000/node_modules/.vite/chunk-VP3FZ6LR.js?v=60c87e0f:25:44)
at node_modules/@node-redis/client/dist/lib/client/index.js (http://localhost:3000/node_modules/.vite/chunk-L35TFNQI.js?v=60c87e0f:9192:20)
at __require (http://localhost:3000/node_modules/.vite/chunk-VP3FZ6LR.js?v=60c87e0f:25:44)
at node_modules/@node-redis/client/dist/index.js (http://localhost:3000/node_modules/.vite/redis.js?v=60c87e0f:852:20)
at __require (http://localhost:3000/node_modules/.vite/chunk-VP3FZ6LR.js?v=60c87e0f:25:44)
at node_modules/redis/dist/index.js (http://localhost:3000/node_modules/.vite/redis.js?v=60c87e0f:2589:20)
at __require (http://localhost:3000/node_modules/.vite/chunk-VP3FZ6LR.js?v=60c87e0f:25:44)
at http://localhost:3000/node_modules/.vite/redis.js?v=60c87e0f:2615:21
This is my redis file (even with only this much, I get the same error)
import redis from 'redis'
export var str = "sample string"
This is my svelte component's script
<script lang="ts">
import { str } from "../redis_test";
</script>
Solution 1:[1]
I've had a similar problem and my understanding from reading the above is that it caused because the browser client is trying to read the db which is on the server. I am also using sveltekit and I resolved by problem by making sure my code was in an endpoint, which only runs on the server and then invoked the endpoint to get my data.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aidan Nichol |
