This is probably not a bug, but more likely a lack of knowledge on my part.
I’m trying to use Dgraph-js-http
with Sveltekit (SvelteKit v1.0.0-next.114
).
I have the following javascript, to create a store
:
import {writable} from "svelte/store";
export const resume_store = writable([]);
import {dgraph} from 'dgraph-js-http';
// import grpc from 'grpc';
// const dgraph = require("dgraph-js");
// const grpc = require("grpc");
const clientStub = new dgraph.DgraphClientStub(
// addr: optional, default: "http://localhost:8080"
"http://localhost:8080",
// legacyApi: optional, default: false. Set to true when connecting to Dgraph v1.0.x
false,
);
const dgraphClient = new dgraph.DgraphClient(clientStub);
...
//create query etc
Error
However, when I run npm run dev
I get the following error:
11:31:07 am [vite] Error when evaluating SSR module /stores/resume.js:
TypeError: Cannot read property 'DgraphClientStub' of undefined
at /stores/resume.js:11:31
at instantiateModule (/home/anton/git/resume-web/node_modules/vite/dist/node/chunks/dep-cb562f8f.js:68783:166)
Cannot read property 'DgraphClientStub' of undefined
TypeError: Cannot read property 'DgraphClientStub' of undefined
at /stores/resume.js:11:31
at instantiateModule (/home/anton/git/resume-web/node_modules/vite/dist/node/chunks/dep-cb562f8f.js:68783:166)
What Dgraph client (and version) are you using?
(put “x” in the box to select)
- Dgo
- PyDgraph
- Dgraph4J
- Dgraph-js
- Dgraph-js-http
- Dgraph.NET
Version: 21.3.1
Update
I was able to move past the above error by using the following:
import * as dgraph from 'dgraph-js-http';
Now the error I’m facing is:
500
Buffer2 is undefined
node_modules/safe-buffer/index.js@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=43e3f0da:554:9
__require@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=43e3f0da:7:44
node_modules/jws/lib/sign-stream.js@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=43e3f0da:1126:19
__require@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=43e3f0da:7:44
node_modules/jws/index.js@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=43e3f0da:1306:22
__require@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=43e3f0da:7:44
node_modules/jsonwebtoken/decode.js@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=43e3f0da:1339:15
__require@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=43e3f0da:7:44
node_modules/jsonwebtoken/index.js@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=43e3f0da:3396:15
__require@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=43e3f0da:7:44
node_modules/dgraph-js-http/lib/clientStub.js@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=43e3f0da:3598:15
__require@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=43e3f0da:7:44
node_modules/dgraph-js-http/lib/index.js@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=43e3f0da:4587:18
__require@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=43e3f0da:7:44
@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=43e3f0da:4595:30