问题描述
我正在尝试从 sveltekit (svelteKit v1.0.0-next.114
) 应用程序调用 GRPC 服务(dGraph api)。
我正在使用来自 writable
的 svelte/store
存储,并且能够将调用 GRPC 服务的响应记录到控制台。
但是,我们将 store 导入到我的 svelte 组件中,使用以下命令,我收到以下错误。
<script>
import {resume_store} from '../../stores/resume';
console.log($resume_store);
</script>
错误
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
替代 Dqraph 客户端
我也尝试使用 dgraph-js-http 客户端。
观察结果(见下文)是相同的 - 有一小段时间页面看起来符合预期。
首先,我收到一个错误,看起来与 https://github.com/vitejs/vite/issues/2579 中描述的一样。但是,我没有保存这个,所以不能在这里粘贴确切的错误。
然后我尝试了
- 删除
node_modules
- 正在运行
npm install
- 正在运行
npm dev run
然后,然而发生了以下错误。
错误 - Buffer2 未定义
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
其他尝试包括:
- 将
export const hydrate = false;
添加到.svelte
文件中,但这没有任何区别。 - 与上述点相关,我尝试将
context="module"
添加到<script>
标签,因为这在与 hydr 相关的 sveltekit 文档中显示 - 请参阅 https://kit.svelte.dev/docs#ssr-and-javascript-hydrate。然而,这导致了Cannot reference store value inside <script context="module">
的错误
观察
sveltekit 应用程序的网页有一小段时间显示了 dgraph grpc 服务调用的结果 - 也许一秒钟。然后显示上面的错误信息。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)