I'm trying to call a GRPC service (a dGraph api) from a Sveltekit (SvelteKit v1.0.0-next.114
) application.
I am using a writable
store from svelte/store
, and am able to log to the console the response from calling the GRPC service.
However, we I import the store into my svelte component, using the following, I get the below error.
<script>
import {resume_store} from '../../stores/resume';
console.log($resume_store);
</script>
Error
500
process is not defined
node_modules/@grpc/grpc-js/build/src/logging.js@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:9012:28
__require@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:7:44
node_modules/@grpc/grpc-js/build/src/metadata.js@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:9057:21
__require@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:7:44
node_modules/@grpc/grpc-js/build/src/call-credentials.js@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:9231:22
__require@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:7:44
node_modules/@grpc/grpc-js/build/src/index.js@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:15325:30
__require@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:7:44
node_modules/dgraph-js/lib/util.js@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:15483:16
__require@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:7:44
node_modules/dgraph-js/lib/types.js@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:15595:18
__require@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:7:44
node_modules/dgraph-js/lib/dgraph.js@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:17224:15
__require@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:7:44
node_modules/dgraph-js/lib/index.js@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:17254:18
__require@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:7:44
@http://localhost:3000/node_modules/.vite/dgraph-js.js?v=d2c49382:17261:25
Alternative Dqraph client
I also tried using dgraph-js-http client.
The observations (see below) were the same - that being, for a brief moment the page looked as expected.
Firstly, I was getting an error that looked like it was the same as described on https://github.com/vitejs/vite/issues/2579. However, I didnt save this, so cannot paste the exact error here.
I then tried
- deleting the
node_modules
- running
npm install
- running
npm dev run
Then, however the following error occurred.
Error - Buffer2 is undefined
500
Buffer2 is undefined
node_modules/safe-buffer/index.js@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=e33d301e:554:9
__require@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=e33d301e:7:44
node_modules/jws/lib/sign-stream.js@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=e33d301e:1126:19
__require@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=e33d301e:7:44
node_modules/jws/index.js@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=e33d301e:1306:22
__require@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=e33d301e:7:44
node_modules/jsonwebtoken/decode.js@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=e33d301e:1339:15
__require@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=e33d301e:7:44
node_modules/jsonwebtoken/index.js@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=e33d301e:3396:15
__require@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=e33d301e:7:44
node_modules/dgraph-js-http/lib/clientStub.js@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=e33d301e:3598:15
__require@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=e33d301e:7:44
node_modules/dgraph-js-http/lib/index.js@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=e33d301e:4587:18
__require@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=e33d301e:7:44
@http://localhost:3000/node_modules/.vite/dgraph-js-http.js?v=e33d301e:4595:30
Other attempts included:
- Adding
export const hydrate = false;
to the.svelte
file, however this made no difference. - Related to the above point, I tried adding
context="module"
to the<script>
tag, as this is what is shown in the Sveltekit docs related to hydrate - see https://kit.svelte.dev/docs#ssr-and-javascript-hydrate. However this resulted in an error ofCannot reference store value inside <script context="module">
Observations
For a brief moment the web page of the Sveltekit application does display the result from the dgraph grpc service call - for maybe a second. Then the error message, above, is displayed.