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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章