Node.js application SyntaxError: Unexpected reserved word 'class'
Node.js application SyntaxError: Unexpected reserved word 'class'
我是 Node.js 的新手,刚开始使用 Eclipse 和 Nodeclipse 插件构建应用程序。当我 运行 使用 Node core.js 的应用程序时它工作正常,但是使用 Eclipse 它显示以下错误:
/home/sarojs/projects/Core/security.js:3
class Security {
^^^^^
SyntaxError: Unexpected reserved word
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/home/sarojs/projects/node/liveprojects/ecurvInc/Core/core.js:12:16)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
我不知道这里出了什么问题。我搜索了解决方案并找到了一些资源 Unexpected reserved word,但我不明白如何将其合并到 Eclipse 中。
我的 package.json 看起来像这样:
{
"dependencies": {
"bluebird": "^3.4.0",
"body-parser": "~1.8.1",
"cookie-parser": "~1.3.3",
"cors": "^2.8.1",
"debug": "~2.0.0",
"express": "~4.9.0",
"express-handlebars": "^3.0.0",
"express-session": "^1.13.0",
"mysql": "^2.11.1",
"passport": "^0.3.2",
"passport-local": "^1.0.0"
}
}
- Node.js版本:4.4.6
- IDE:带有 Nodeclipse 插件的 Eclipse Mars 1
非常感谢任何帮助。
class
声明是一个 ES6 特性。 ES6 具有 are hardly supported in node 4.4.6. Try updating 它和 运行 npm install
又
另见 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class
我挠了挠头解决了这个问题
正如@Tom M 所说,class 声明是一个 ES6 功能,之前我有节点 4.2.6,但是当我将它更新到 v4.6.2 时,错误消失了。
我从 here 下载二进制文件并通过手动将文件解压缩到我的 /usr/local 目录然后 运行
安装节点
npm install
您可以找到如何手动安装节点二进制文件here
JavaScript classes 是最近在 ECMAScript 6 中引入的。它们是之前原型继承模型的语法糖。
您可以检查哪个版本的节点支持 class 语法超过 node.green
您可以看到 v4.6.2 支持 class 概念,因此请尝试将其至少更新到 4.6。2.But 此版本不支持所有 ES6 功能。
我是 Node.js 的新手,刚开始使用 Eclipse 和 Nodeclipse 插件构建应用程序。当我 运行 使用 Node core.js 的应用程序时它工作正常,但是使用 Eclipse 它显示以下错误:
/home/sarojs/projects/Core/security.js:3
class Security {
^^^^^
SyntaxError: Unexpected reserved word
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/home/sarojs/projects/node/liveprojects/ecurvInc/Core/core.js:12:16)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
我不知道这里出了什么问题。我搜索了解决方案并找到了一些资源 Unexpected reserved word,但我不明白如何将其合并到 Eclipse 中。
我的 package.json 看起来像这样:
{
"dependencies": {
"bluebird": "^3.4.0",
"body-parser": "~1.8.1",
"cookie-parser": "~1.3.3",
"cors": "^2.8.1",
"debug": "~2.0.0",
"express": "~4.9.0",
"express-handlebars": "^3.0.0",
"express-session": "^1.13.0",
"mysql": "^2.11.1",
"passport": "^0.3.2",
"passport-local": "^1.0.0"
}
}
- Node.js版本:4.4.6
- IDE:带有 Nodeclipse 插件的 Eclipse Mars 1
非常感谢任何帮助。
class
声明是一个 ES6 特性。 ES6 具有 are hardly supported in node 4.4.6. Try updating 它和 运行 npm install
又
另见 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class
我挠了挠头解决了这个问题
正如@Tom M 所说,class 声明是一个 ES6 功能,之前我有节点 4.2.6,但是当我将它更新到 v4.6.2 时,错误消失了。
我从 here 下载二进制文件并通过手动将文件解压缩到我的 /usr/local 目录然后 运行
安装节点 npm install
您可以找到如何手动安装节点二进制文件here
JavaScript classes 是最近在 ECMAScript 6 中引入的。它们是之前原型继承模型的语法糖。
您可以检查哪个版本的节点支持 class 语法超过 node.green
您可以看到 v4.6.2 支持 class 概念,因此请尝试将其至少更新到 4.6。2.But 此版本不支持所有 ES6 功能。