运行gulp server时出现Unexpected token语法错误
解决CentOS7运行pdf.js的gulp server报SyntaxError问题
问题根源
CentOS7默认自带的Node.js版本(通常为v10或更早)不支持ES2020的可选链操作符(?.),而pdf.js的gulpfile.js中使用了该语法,导致编译时抛出SyntaxError: Unexpected token .错误。
修复步骤
升级Node.js到v14及以上版本
- 卸载系统旧版本Node.js:
yum remove -y nodejs npm - 配置NodeSource的v14版本源:
curl -sL https://rpm.nodesource.com/setup_14.x | bash - - 安装新版本Node.js:
yum install -y nodejs - 验证版本是否达标:
输出需为node -vv14.x.x或更高版本。
- 卸载系统旧版本Node.js:
重新安装项目依赖
删除旧依赖文件后重新安装:rm -rf node_modules package-lock.json npm install重启服务
再次执行启动命令:gulp server
内容的提问来源于stack exchange,提问作者unice
相关产品推荐
相关产品推荐

