导入npm的ssh2模块后出错

时间:2017-12-11 18:38:20

标签: reactjs ssh npm libssh2

我的任务是将ssh写入集群并执行spark代码。这必须从浏览器完成。我正在使用Reactjs从NPM构建UI和'ssh2'来访问集群。当我使用以下代码时。

var Client = require('ssh2').Client;

我收到了以下警告和错误消息。

WARNING in ./node_modules/defaultable/defaultable.js
49:13-31 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/defaultable/defaultable.js
 @ ./node_modules/hbo-dnsd/server.js
 @ ./node_modules/hbo-dnsd/named.js
 @ ./node_modules/dns/lib/dns.js
 @ ./node_modules/ssh2/lib/client.js
 @ ./App.jsx
 @ ./main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./main.js

ERROR in ./node_modules/ssh2/lib/agent.js
Module not found: Error: Can't resolve 'child_process' in '/Users/byra/Work/reactTest/node_modules/ssh2/lib'
 @ ./node_modules/ssh2/lib/agent.js 6:9-33
 @ ./node_modules/ssh2/lib/client.js
 @ ./App.jsx
 @ ./main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./main.js

ERROR in ./node_modules/native-dns-cache/lookup.js
Module not found: Error: Can't resolve 'dgram' in '/Users/byra/Work/reactTest/node_modules/native-dns-cache'
 @ ./node_modules/native-dns-cache/lookup.js 21:12-28
 @ ./node_modules/native-dns-cache/index.js
 @ ./node_modules/native-dns/lib/platform.js
 @ ./node_modules/native-dns/dns.js
 @ ./node_modules/dns/lib/dns.js
 @ ./node_modules/ssh2/lib/client.js
 @ ./App.jsx
 @ ./main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./main.js

ERROR in ./node_modules/native-dns/lib/server.js
Module not found: Error: Can't resolve 'dgram' in '/Users/byra/Work/reactTest/node_modules/native-dns/lib'
 @ ./node_modules/native-dns/lib/server.js 23:12-28
 @ ./node_modules/native-dns/dns.js
 @ ./node_modules/dns/lib/dns.js
 @ ./node_modules/ssh2/lib/client.js
 @ ./App.jsx
 @ ./main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./main.js

ERROR in ./node_modules/native-dns/lib/utils.js
Module not found: Error: Can't resolve 'dgram' in '/Users/byra/Work/reactTest/node_modules/native-dns/lib'
 @ ./node_modules/native-dns/lib/utils.js 21:12-28
 @ ./node_modules/native-dns/lib/server.js
 @ ./node_modules/native-dns/dns.js
 @ ./node_modules/dns/lib/dns.js
 @ ./node_modules/ssh2/lib/client.js
 @ ./App.jsx
 @ ./main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./main.js

ERROR in ./node_modules/native-dns/lib/platform.js
Module not found: Error: Can't resolve 'fs' in '/Users/byra/Work/reactTest/node_modules/native-dns/lib'
 @ ./node_modules/native-dns/lib/platform.js 23:9-22
 @ ./node_modules/native-dns/dns.js
 @ ./node_modules/dns/lib/dns.js
 @ ./node_modules/ssh2/lib/client.js
 @ ./App.jsx
 @ ./main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./main.js

ERROR in ./node_modules/request/lib/har.js
Module not found: Error: Can't resolve 'fs' in '/Users/byra/Work/reactTest/node_modules/request/lib'
 @ ./node_modules/request/lib/har.js 3:9-22
 @ ./node_modules/request/request.js
 @ ./node_modules/request/index.js
 @ ./node_modules/webhdfs/lib/webhdfs.js
 @ ./App.jsx
 @ ./main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./main.js

ERROR in ./node_modules/ssh2-streams/lib/sftp.js
Module not found: Error: Can't resolve 'fs' in '/Users/byra/Work/reactTest/node_modules/ssh2-streams/lib'
 @ ./node_modules/ssh2-streams/lib/sftp.js 6:16-29 11:9-22
 @ ./node_modules/ssh2-streams/index.js
 @ ./node_modules/ssh2/lib/client.js
 @ ./App.jsx
 @ ./main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./main.js

ERROR in ./node_modules/ssh2/lib/agent.js
Module not found: Error: Can't resolve 'fs' in '/Users/byra/Work/reactTest/node_modules/ssh2/lib'
 @ ./node_modules/ssh2/lib/agent.js 5:9-22
 @ ./node_modules/ssh2/lib/client.js
 @ ./App.jsx
 @ ./main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./main.js

ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'tls' in '/Users/byra/Work/reactTest/node_modules/forever-agent'
 @ ./node_modules/forever-agent/index.js 7:10-24
 @ ./node_modules/request/request.js
 @ ./node_modules/request/index.js
 @ ./node_modules/webhdfs/lib/webhdfs.js
 @ ./App.jsx
 @ ./main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./main.js

ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'tls' in '/Users/byra/Work/reactTest/node_modules/tunnel-agent'
 @ ./node_modules/tunnel-agent/index.js 4:10-24
 @ ./node_modules/request/lib/tunnel.js
 @ ./node_modules/request/request.js
 @ ./node_modules/request/index.js
 @ ./node_modules/webhdfs/lib/webhdfs.js
 @ ./App.jsx
 @ ./main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./main.js
webpack: Failed to compile.

我尝试通过添加

来更改webpack.config.js文件
target: 'node'

node: {
        console: false,
        fs: 'empty',
        net: 'empty',
        tls: 'empty'
    },

尽管如此,问题仍然存在。我该如何解决这个问题?是否有另一种方法可以进入群集?

1 个答案:

答案 0 :(得分:0)

我试图从Web浏览器进入群集,该浏览器不支持或不需要协议执行所需的任务。所以,最好在后端做。