NW.JS无法加载grpc二进制模块

时间:2018-05-22 20:35:05

标签: node.js google-cloud-platform node-webkit grpc nwjs

我正在尝试构建一个需要gRPC模块的应用程序。从命令提示符运行时,我的应用程序运行正常 - node server.js

但是,运行nwjs会崩溃并抛出下面的错误 -

我尝试了什么 -

1。如果我启用 window.location.href =' http://localhost:3000';     然后nwjs windows显示 localhost 此站点无法访问localhost拒绝连接。并且在显示错误后控制台被清除所以我评论了这个行看到错误。 (错误日志如下所示)

Uncaught Error: Failed to load gRPC binary module because it was not installed for the current system
Expected directory: node-webkit-v0.30.5-win32-x64-unknown
Found: [node-v57-win32-x64-unknown]
This problem can often be fixed by running "npm rebuild" on the current system
Original error: Cannot find module 'C:\Users\BLACK\Desktop\NWJS Xperiments\NuOS-OAuth\node_modules\grpc\src\node\extension_binary\node-webkit-v0.30.5-win32-x64-unknown\grpc_node.node'
    at Object.<anonymous> (C:\Users\BLACK\Desktop\NWJS Xperiments\NuOS-OAuth\node_modules\grpc\src\grpc_extension.js:53:17)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:719:10)
    at Module.load (internal/modules/cjs/loader.js:613:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:552:12)
    at Function.Module._load (internal/modules/cjs/loader.js:544:3)
    at Module.require (internal/modules/cjs/loader.js:650:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (C:\Users\BLACK\Desktop\NWJS Xperiments\NuOS-OAuth\node_modules\grpc\src\client_interceptors.js:145:12)
    at Module._compile (internal/modules/cjs/loader.js:702:30)

2. 我手动创建了预期目录 - &#34;预期目录:node-webkit-v0.30.5-win32-x64-unknown&#34;在grpc模块中,但现在我在开发工具中看到了另一个错误,认为它解决了上述问题。

Uncaught Error: A dynamic link library (DLL) initialization routine failed.
\\?\C:\Users\BLACK\Desktop\NWJS Xperiments\NuOS-OAuth\node_modules\grpc\src\node\extension_binary\node-webkit-v0.30.5-win32-x64-unknown\grpc_node.node
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:749:18)
    at Module.load (internal/modules/cjs/loader.js:613:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:552:12)
    at Function.Module._load (internal/modules/cjs/loader.js:544:3)
    at Module.require (internal/modules/cjs/loader.js:650:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (C:\Users\BLACK\Desktop\NWJS Xperiments\NuOS-OAuth\node_modules\grpc\src\grpc_extension.js:32:13)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:719:10)
    at Module.load (internal/modules/cjs/loader.js:613:32)

3。我按照here的说明操作,但也没有运气。它引发了另一组错误。

在第三点尝试说明后,我收到此错误

> grpc@1.11.3 install C:\Users\BLACK\Desktop\NWJS Xperiments\NuOS-OAuth\node_modules\grpc
> node-pre-gyp install --fallback-to-build --library=static_library

node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute 'nw-gyp.cmd configure --fallback-to-build --library=static_library --module=C:\Users\BLACK\Desktop\NWJS Xperiments\NuOS-OAuth\node_modules\grpc\src\node\extension_binary\node-webkit-v1.11.3-win32-x64-unknown\grpc_node.node --module_name=grpc_node --module_path=C:\Users\BLACK\Desktop\NWJS Xperiments\NuOS-OAuth\node_modules\grpc\src\node\extension_binary\node-webkit-v1.11.3-win32-x64-unknown --napi_version=1 --node_abi_napi=napi' (Error: spawn nw-gyp.cmd ENOENT)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (C:\Users\BLACK\Desktop\NWJS Xperiments\NuOS-OAuth\node_modules\grpc\node_modules\node-pre-gyp\lib\util\compile.js:77:29)
node-pre-gyp ERR! stack     at emitOne (events.js:116:13)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:211:7)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:196:12)
node-pre-gyp ERR! stack     at onErrorNT (internal/child_process.js:372:16)
node-pre-gyp ERR! stack     at _combinedTickCallback (internal/process/next_tick.js:138:11)
node-pre-gyp ERR! stack     at process._tickCallback (internal/process/next_tick.js:180:9)
node-pre-gyp ERR! System Windows_NT 10.0.17134
node-pre-gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\BLACK\\Desktop\\NWJS Xperiments\\NuOS-OAuth\\node_modules\\grpc\\node_modules\\node-pre-gyp\\bin\\node-pre-gyp" "install" "--fallback-to-build" "--library=static_library"
node-pre-gyp ERR! cwd C:\Users\BLACK\Desktop\NWJS Xperiments\NuOS-OAuth\node_modules\grpc
node-pre-gyp ERR! node -v v8.10.0
node-pre-gyp ERR! node-pre-gyp -v v0.10.0
node-pre-gyp ERR! not ok
Failed to execute 'nw-gyp.cmd configure --fallback-to-build --library=static_library --module=C:\Users\BLACK\Desktop\NWJS Xperiments\NuOS-OAuth\node_modules\grpc\src\node\extension_binary\node-webkit-v1.11.3-win32-x64-unknown\grpc_node.node --module_name=grpc_node --module_path=C:\Users\BLACK\Desktop\NWJS Xperiments\NuOS-OAuth\node_modules\grpc\src\node\extension_binary\node-webkit-v1.11.3-win32-x64-unknown --napi_version=1 --node_abi_napi=napi' (Error: spawn nw-gyp.cmd ENOENT)
npm WARN nuos-healthcare@1.0.0 No description
npm WARN nuos-healthcare@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! grpc@1.11.3 install: `node-pre-gyp install --fallback-to-build --library=static_library`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the grpc@1.11.3 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\BLACK\AppData\Roaming\npm-cache\_logs\2018-05-23T01_42_49_740Z-debug.log

Server.JS

const express = require('express'),
    bodyParser = require('body-parser'),
    socket = require('socket.io'),
    BigTable = require('@google-cloud/bigtable'),
    PubSub = require('@google-cloud/pubsub'),
    passport = require('passport'),
    mongoose = require('mongoose'),
    cookieSession = require('cookie-session'),
    dotenv = require('dotenv').config(),
    config = require('./config/config'),
    gutils = require('./app/gutils'),
    authRoutes = require('./routes/auth-route'),
    passportSetup = require('./app/passport-setup'),
    app = express(),
    server = app.listen(3000),
    io = socket(server);

/*


App code removed 


*/


app.get('/', (req, res) => {
    res.render('login');
});

app.use(express.static('public'));

console.log('Server running on the port 3000 ...'); 

P.S。如果我在cmd中运行 node server.js 命令然后运行nwjs,它的工作正常。

我正在开发Windows 10 x64

1 个答案:

答案 0 :(得分:0)

我的方法会有所不同。首先,您不能将node.js应用程序和nwjs放在相同的文件夹结构中,因为它们安装节点模块的方式不同。

您应该做什么。

  1. 按照http://docs.nwjs.io/en/latest/For%20Users/Getting%20Started/
  2. 中所述创建基本的NWJS应用程序

您可以选择最新版本,但请记住使用哪个版本,因为在安装grpc时需要知道该版本。

  1. 现在,您必须安装要使用的grpc。

    npm install grpc --build-from-source --runtime=node-webkit --target=0.32.2 --target_arch=x64
    

请清楚您在1中所描述的NWJS版本。最新的是0.32.2。 并将target_arch设置为x64

  1. 现在将代码逐步复制到您的nwjs应用程序中并运行它。 NWJS与node.js应用程序不同。因此,重要的是将node.js代码和NWJS代码分开。