012 Node.js服务端:运行node项目出现Unexpected token,但是本地测试没问题(Nodejs版本更新)

运行node项目出现Unexpected token,但是本地测试没问题

[nodemon] starting `node index.js`
/www/wwwroot/nodeserver/wzry/server/routes/admin/index.js:11
    router.post('/', async (req, res) => {
                           ^

SyntaxError: Unexpected token (
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/www/wwwroot/nodeserver/wzry/server/index.js:12:1)
[nodemon] app crashed - waiting for file changes before starting...

查找了很多解决方案,后面发现是node低版本不支持Es6语法,到了Node 7.6(V8版本 5.5)后才完全支持async, await关键字。
所以,现在需要将nodejs版本进行一次更新!

Node.js更新新版本

第一步:先清除npm缓存:npm cache clean -f
第二步:安装n模块:npm install -g n
第三步:升级node.js到最新稳定版:n stable
简单三步,完成node.js的版本更新操作!
参考资料:https://blog.csdn.net/z15802933724/article/details/82346776

posted @ 2019-11-04 01:58  南风S  阅读(405)  评论(0)    收藏  举报