【问题标题】:Unexpected Token } | But I cannot find it意外令牌} |但我找不到它
【发布时间】:2019-06-23 02:31:04
【问题描述】:

我正在使用 nodejs 为我的网站设置一个随机发生器,但我在脚本末尾不断收到 SyntaxError。我个人找不到它并请求帮助(如果有)!

到目前为止,我一直在向上看,看看错误是否在代码中更远,但什么也没找到。

function time() {
  return parseInt(new Date().getTime()/1000)
}

function generate(count) {
    return crypto.randomBytes(count).toString('hex');
}

function array_limit(wartosc){
  if(chat_history.length==25){
    chat_history.shift();
    chat_history.shift();
  }
  chat_history.push(wartosc);
}

function jp_limit(wartosc){
  if(jpWinners.length==10){
    jpWinners.shift();
  }
  jpWinners.push(wartosc);
}
function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min);
} //this is the error line

我相信这应该可以正常运行,我的控制台输出如下,也许我犯了一个错误,但我正在认真考虑去看最近的眼科医生! :

    :2241
});
^

SyntaxError: Unexpected token }
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:617:28)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3

Edit1:当前版本是版本 (8.16.0-1nodesource1)。

Config.js

var config = {};

config.db = '';
config.host = '';
config.user = '';
config.password = '';

config.admin = '';
config.botsteamid = {bot1:''};
config.identitysecret = '';
config.sharedsecret = '';
config.polling_interval  = 5000;

config.bot_username = '';
config.bot_password = '';

config.manager_domain = '';
config.manager_lang = 'en';
config.manager_cancelTime = 60000;

module.exports = config;

我删除了一些敏感数据*

【问题讨论】:

  • 欢迎来到 SO!我注意到您的错误与代码不匹配,该代码没有这样的});。你能用minimal reproducible example澄清一下吗?
  • @ggorlen 问题是这个文件接近 2241 行,因为我看不到问题,所以无法正确解决问题,});不匹配,这就是我难过的原因。
  • 我明白,但看不到代码的人似乎不太可能确定问题所在。 balancebraces.com 怎么样?
  • 这个问题的错误信息和你的一模一样(不同的堆栈跟踪):stackoverflow.com/questions/50042906/…。重新配置文件,这就是 @ggorlen 要求 minimal 可重现示例的原因——从该文件中删除函数和代码片段,直到您拥有显示相同错误的最少代码。
  • 好吧,抱歉不清楚,我说的是改变节点行为的配置文件,比如 webpack.config.js、ts-config.json 或 package.json——诸如此类.这些文件(如果存在于您的项目中)将显示您运行文件时使用的确切堆栈。

标签: javascript node.js


【解决方案1】:

尝试将webpack.config.js 文件的内容移动到next.config.js 文件中

【讨论】:

    猜你喜欢
    • 2019-03-01
    • 1970-01-01
    • 2016-06-14
    • 2015-12-16
    • 2018-02-12
    • 2018-04-20
    • 2016-01-13
    • 1970-01-01
    • 2020-01-01
    相关资源
    最近更新 更多