【问题标题】:Node.js syntax errorNode.js 语法错误
【发布时间】:2017-06-07 06:25:04
【问题描述】:

我想使用 socket.io 和 https://socket.io/get-started/chat/ 用户这个链接来了解我何时尝试运行 node index.js

我遇到了一个错误

const WebSocket = require('./lib/WebSocket');
^^^^^ SyntaxError: Use of const in strict mode.
    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 Server.init (C:\WEBLER\Socket.io\node_modules\socket.io\node_modules\engi ne.io\lib\server.js:119:16)
    at new Server (C:\WEBLER\Socket.io\node_modules\socket.io\node_modules\engin e.io\lib\server.js:65:8)
    at Function.attach (C:\WEBLER\Socket.io\node_modules\socket.io\node_modules\ engine.io\lib\engine.io.js:123:16)

我看了问题。一般人说node.js的升级版 当我运行node --version

答案是 2.7.4 我试过了

npm cache clean -f
npm install stable

node --version

但没有解决。我该如何解决问题?

【问题讨论】:

标签: javascript node.js sockets


【解决方案1】:

我相信,const 仅适用于 node v4.0 及更高版本。您可以按照 Edilson 的建议使用 var,或者将节点从 2.7.4 升级到支持 const 的版本。另外,接受 jsNovice 的建议并使用 nvm。这是其他人遇到的相同问题的链接: https://github.com/felixrieseberg/npm-windows-upgrade/issues/108

【讨论】:

    猜你喜欢
    • 2016-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多