SyntaxError: Unexpected token { while starting
SyntaxError: Unexpected token { while starting
原因:
所以,我在弄乱 node.js 版本(更新),我不小心让我的 node.js 程序不再工作了。这个问题是我不记得我之前有什么 node.js 版本。至少,当我这样做的时候,它就开始发生了。
问题:
当我用 node app.js
启动我的程序时,我得到以下信息:
$ node app.js
/home/sunnlightbro/ftp/discordbot/schwi/app.js:3
const {token} = require(path.join(__dirname, 'auth.json'));
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3
考虑到我的代码在此之前一直有效,现在我知道我的代码是正确的。
PS:考虑到我使用了很多变量,其他 类 中需要 { }
。恰好是在这种令牌情况下它只有 1 个变量。
代码:
const path = require('path');
const Ononoki = require(path.join(__dirname, 'Ononoki.js'));
const {token} = require(path.join(__dirname, 'auth.json'));
start = function () {
new Ononoki(token).init();
};
start();
老实说,除了节点版本或其他错误之外,我不知道其他原因。感谢您的回复。
尝试在根文件夹中删除 node_modules 和 运行 npm install。
$ rm -rf node_modules/
$ npm update
$ npm install
原因:
所以,我在弄乱 node.js 版本(更新),我不小心让我的 node.js 程序不再工作了。这个问题是我不记得我之前有什么 node.js 版本。至少,当我这样做的时候,它就开始发生了。
问题:
当我用 node app.js
启动我的程序时,我得到以下信息:
$ node app.js
/home/sunnlightbro/ftp/discordbot/schwi/app.js:3
const {token} = require(path.join(__dirname, 'auth.json'));
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3
考虑到我的代码在此之前一直有效,现在我知道我的代码是正确的。
PS:考虑到我使用了很多变量,其他 类 中需要 { }
。恰好是在这种令牌情况下它只有 1 个变量。
代码:
const path = require('path');
const Ononoki = require(path.join(__dirname, 'Ononoki.js'));
const {token} = require(path.join(__dirname, 'auth.json'));
start = function () {
new Ononoki(token).init();
};
start();
老实说,除了节点版本或其他错误之外,我不知道其他原因。感谢您的回复。
尝试在根文件夹中删除 node_modules 和 运行 npm install。
$ rm -rf node_modules/
$ npm update
$ npm install