如何将 google 数据存储包添加到电子应用程序

How to add google datastore package to electron app

我的第一个电子应用程序:它是一个管理应用程序,旨在 运行 仅在我的机器上

我想添加@google-cloud/datastore模块,但是导入包后electron无法启动

我使用 'yarn add' 添加包,然后按照此处的说明使用 electron-rebuild 为 electron 重建:https://electronjs.org/docs/tutorial/using-native-node-modules

第一个错误是:

Failed to compile
./node_modules/@grpc/grpc-js/build/src/channel.js
Module not found: Can't resolve 'http2' in '<...>\node_modules\@grpc\grpc-js\build\src'

所以我尝试手动添加 http2、electron-rebuild 和 'yarn start',之后我收到一些警告:

./node_modules/http2/lib/protocol/index.js                                                                                                              
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted                                            
./node_modules/grpc/src/grpc_extension.js                                                                                                               
Critical dependency: the request of a dependency is an expression                                                                                      
./node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js                                                                                       
Critical dependency: the request of a dependency is an expression                                                                                      
./node_modules/grpc/node_modules/node-pre-gyp/lib/util/versioning.js 

应用随后启动,但显示一长串错误。

Error: Cannot find module './../process/browser.js'
... intermediate errors, below is the module trying to import
Module../node_modules/merge2/index.mjs

我不确定 if/what 我做错了,或者 google 数据存储是否与电子不兼容?

使用最新的 Electron 和 google 软件包(没有其他更改)似乎已经解决了这个问题