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

GitLab部署Firebase Functions遇非法选项错误,转Unix EOL无效

GitLab部署Firebase Functions报错排查(/bin/sh: 0: Illegal option --)

问题场景

在GitLab环境部署Firebase Functions时触发predeploy报错,已将package.json和firebase.json转换为Unix换行符(EOL),但问题仍未解决。报错信息如下:

i  deploying storage, firestore, functions, hosting
Running command: npm --prefix "$RESOURCE_DIR" run lint
> lint
> tslint -p tsconfig.json
/bin/sh: 0: Illegal option --
Error: functions predeploy error: Command terminated with non-zero exit code 2

附带的package.json核心配置:

{
  "name": "functions",
  "scripts": {
    "test": "mocha --timeout 15000 -r ts-node/register './test/*/*.ts' --exit",
    "lint": "tslint -p tsconfig.json",
    "build": "tsc",
    "build:watch": "tsc --watch --preserveWatchOutput",
    "serve": "npm run build:watch | firebase emulators:start --only functions",
    "serve:all": "npm run build:watch | firebase emulators:start --import ./fs-export --inspect-functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "10"
  },
  "dependencies": {
    "firebase": "^7.16.0",
    "firebase-admin": "^8.10.0",
    "firebase-functions": "^3.6.1"
  },
  "devDependencies": {
    "tslint": "^5.20.1",
    "typescript": "^3.8.0",
    "typings": "^2.1.1"
  },
  "private": true
}

可能的原因及排查方向

  • 隐藏特殊字符残留
    仅转换换行符可能不够,package.json或tsconfig.json中可能存在其他Windows特殊字符(如不可见的控制字符)。在GitLab CI环境中执行cat -A package.json命令,查看行尾或命令参数是否有^M以外的异常符号,这些符号会干扰shell解析命令。

  • Git自动换行符转换干扰
    Git默认会在拉取代码时自动转换换行符,即使本地已设置Unix格式,推送到GitLab后仍可能被修改。在项目根目录添加.gitattributes文件,写入*.json text eol=lf,强制Git对JSON文件保持Unix换行符,避免自动转换。

  • Shell环境差异导致命令解析失败
    GitLab CI默认使用sh而非bash,部分命令参数在sh下会出现解析问题。可以尝试修改lint命令为npx tslint -p tsconfig.json,直接用npx调用依赖包,避免路径或shell解析冲突;也可在package.json中添加"shell": "/bin/bash"指定脚本执行的shell环境(需确认GitLab环境支持)。

  • tsconfig.json格式或换行符问题
    报错虽指向lint命令,但可能是tsconfig.json本身存在格式错误或未转换为Unix换行符,导致tslint解析失败间接引发shell报错。检查该文件的换行符和JSON格式正确性。

  • Node.js版本不兼容
    package.json指定Node.js版本为10,若GitLab CI环境的Node.js版本与之不匹配,或版本过旧/过新,可能导致tslint运行异常。在GitLab CI配置中明确使用node:10镜像,或升级Node.js版本到稳定LTS版本(如14/16),同时同步更新依赖包版本。


内容的提问来源于stack exchange,提问作者Manvydas J Jauga

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 14:10:33