作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发 Steam 项目。为此,我正在使用 node-steam 模块。我在登录部分。我在尝试使用 node-steam 登录 Steam 帐户时遇到此异常异常如下:
Uncaught TypeError: undefined is not a function MYAPP/node_modules/adm-zip/zipFile.js:8
Module.exports /MYAPP/node_modules/adm-zip/zipFile.js:8
module.exports /MYAPP/node_modules/adm-zip/adm-zip.js:25
handlers.(anonymous function) /MYAPP/node_modules/steam/lib/steam_client.js:252
SteamClient._netMsg`enter code here`Received /MYAPP/node_modules/steam/lib/steam_client.js:157
emitOne events.js:75
emit events.js:150
Connection._readPacket /MYAPP/node_modules/steam/lib/connection.js:50
emitNone events.js:65
EMIT events.js:147
emitReadable__ _stream_readable.js:408
emitReadable _stream_readable.js:402
readableAddChunk _stream_readable.js:157
Readable.push _stream_readable.js:109
onread net.js:510
Error: Disconnected
at SteamClient._disconnected (/MYAPP/node_modules/steam/lib/steam_client.js:186:24)
at emitOne (events.js:75:13)
at Connection.emit (events.js:150:7)
at TCP.close (net.js:457:12)
我的源代码如下:
var fs = require('fs');
var Steam = require('steam');
var crypto = require('crypto');
var serverlist = [] //server list here
Steam.servers = serverlist;
var steamClient = new Steam.SteamClient();
var steamUser = new Steam.SteamUser(steamClient);
steamClient.connect();
steamUser.on('updateMachineAuth', function (sentry, callback) {
console.log('writing to file sentry');
fs.writeFileSync('sentry', sentry.bytes);
callback({ sha_file: getSHA1(sentry.bytes) });
});
function getSHA1(bytes) {
var shasum = crypto.createHash('sha1');
shasum.end(bytes);
return shasum.read();
}
steamClient.on('connected', function () {
steamUser.logOn({
account_name: “XXXXXXXX”,
password: “XXXXXXXX”,
// un-comment this when providing secondary auth-code from email
auth_code: ‘XXX’,
sha_sentryfile: getSHA1(fs.readFileSync('sentry'))
});
});
steamUser.on('loggedOn', function () {
console.log('Logged in!');
});
steamClient.on('debug', function (response) {
console.log("debug: " + response);
});
steamClient.on('logOnResponse', function (response) {
console.log(">>logOnResponse");
console.log(response);
if (response.eresult == Steam.EResult.OK) {
console.log('Logged in!');
// Your code here
}
});
steamClient.on('error', function (error) {
console.log(error.stack);
alert("yes error");
});
steamClient.on('servers', function (servers) {
alert(servers);
// fs.writeFile('servers', JSON.stringify(servers));
});
steamClient.on('disconnected', function (s) {
alert(s);
});
以下是我安装的版本。
Node 版本:v10.8.0NPM 版本:6.4.1 Steam 版本:1.4.0操作系统:Mac
请帮我解决这个问题。
最佳答案
正在产生的错误,undefined is not a function
正在发生,因为您正在 node
中调用函数 alert
那是无效的,因为在 Node 中没有这样调用的函数,并且由于您在 errorHandler
中也有该函数,因此应用程序终止。
如果您要删除函数 alert
如果您创建了 console.log()
正在发生的错误应该消失的“警报”函数。
尝试将此函数添加到您的代码或删除所有警报函数:
const alert = () => {
console.log(arguments)
}
关于javascript - 类型错误 : undefined is not a function while logOn to steam,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52166743/
我是一名优秀的程序员,十分优秀!