代码之家  ›  专栏  ›  技术社区  ›  Jitendra

syntaxerror:意外的令牌…在node_modules/express validator/lib/express_validator.js:75中

  •  0
  • Jitendra  · 技术社区  · 6 年前

    我正在尝试使用node server.js运行我的项目,但出现了以下错误。

    /Library/WebServer/Documents/PROJECT/node_modules/express-validator/lib/express_validator.js:75
            chain[name] = (...options) => {
                           ^^^
    
    SyntaxError: Unexpected token ...
        at exports.runInThisContext (vm.js:53:16)
        at Module._compile (module.js:373:25)
        at Object.Module._extensions..js (module.js:416:10)
        at Module.load (module.js:343:32)
        at Function.Module._load (module.js:300:12)
        at Module.require (module.js:353:17)
        at require (internal/module.js:12:17)
        at Object.<anonymous> (/Library/WebServer/Documents/PROJECT/node_modules/express-validator/index.js:1:80)
        at Module._compile (module.js:409:26)
        at Object.Module._extensions..js (module.js:416:10)
    

    我正在使用express.js框架。上次我做的时候,它工作得很好。

    2 回复  |  直到 6 年前
        1
  •  0
  •   Jitendra    6 年前

    在搜索了很多之后,我终于发现我的一个项目是用nodejs的旧版本构建的。 node@4.4.7 在本地计算机上更改节点版本后,使用以下命令:

    nvm ls   // to check out what versions of Node.js are installed on your machine
    
    ->       v4.4.7
             v8.9.1
             system
    default -> 4.4.7 (-> v4.4.7)
    

    从中切换node.js 节点@ 4.4.7 node@8.9.1 我使用了以下命令:

    nvm use v8.9.1
    

    为了验证我再次检查 nvm ls 现在它显示了。

        v4.4.7
    ->       v8.9.1
             system
    default -> 4.4.7 (-> v4.4.7)
    
        2
  •  0
  •   Pratiti Das    6 年前

    是的,ES6中提供的排列运算符将从版本8及更高版本的节点8中提供。