You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署AWS Lambda/Serverless时遭遇SyntaxError: Unexpected token '?'错误

解决Serverless部署时的??语法错误

错误信息

/node_modules/hapi-plugin-websocket/node_modules/@hapi/hoek/lib/contain.js:82
        compare = compare ?? internals.compare(options);
                           ^

SyntaxError: Unexpected token '?'
    at compileFunction (<anonymous>)
    at wrapSafe (internal/modules/cjs/loader.js:1063:16)
    at Module._compile (internal/modules/cjs/loader.js:1111:27)

问题原因

??是空值合并运算符,该语法仅在Node.js 14.0.0及以上版本支持。出现这个错误,说明你的Serverless部署环境使用的Node.js版本低于14.0.0,或者本地开发环境与部署环境的Node.js版本不匹配。

解决方法

  • 检查部署环境Node.js版本:查看Serverless平台的运行时配置,确认当前使用的Node.js版本是否低于14.0.0。
  • 指定兼容的Node.js版本:在Serverless配置文件(如serverless.yml)或平台控制台的运行时设置中,将Node.js版本改为14.x及以上(推荐16.x、18.x等长期支持版本)。
  • 降级依赖(备选):若无法升级Node.js版本,可降级@hapi/hoek到支持低版本Node.js的兼容版本,在package.json中指定具体版本后执行npm install更新依赖。

内容的提问来源于stack exchange,提问作者sxp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 07:22:02