【nodejs项目报错|node-localstorage错误|const ev = opts?.alwaysLast ? ‘afterExit‘ : ‘exit‘;】

nodejs项目报错|node-localstorage错误

系统错误提示:

E:\***\project\gais-middleware\node_modules\signal-exit\dist\cjs\index.js:162
        const ev = opts?.alwaysLast ? 'afterExit' : 'exit';
                        ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (E:\liuy\project\gais-middleware\node_modules\write-file-atomic\lib\index.js:9:20)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

经过排查,导致错误的代码为:

const LocalStorage = require('node-localstorage').LocalStorage;
const localStorage = new LocalStorage('./data');

错误分析:

1.localStorage插件提示的报错信息,错误信息表明Node.js 环境不支持可选链操作符(Optional Chaining Operator)​?.​。可选链操作符是在 ECMAScript 2020(ES11)中引入的,如果 Node.js 版本低于这个版本,那么它将不支持这个特性。
2.完全支持 ECMAScript 2020 特性的 Node.js 版本是 14.0.0 及更高版本
3.查看我自己的nodeJs版本。

PS E:\***\project\gais-middleware> nvm ls

    18.15.0
    16.4.2
  * 12.22.12 (Currently using 64-bit executable)
    8.17.0

版本低于14.0.0,切换版本(没有版本切换的需要下载14.0.0及更高版本)。

nvm use 16.4.2

解决:

PS E:\***\project\gais-middleware> node app.js
启动成功,访问 http://localhost:8071
  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值