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

Firebase部署报错:/bin/sh: 0: Illegal option --问题求助

Firebase部署时Lint检查报错Illegal option --

环境信息

  • firebase --version: 12.9.1
  • node -v: v16.16.0
  • yarn --version: 3.5.0

问题描述

此前已成功部署上千次,每次都会运行lint检查,但现在突然出现Illegal option --错误,导致部署失败。近期升级到Firebase 12.9.1,尝试过降级到12.8.1,也试过删除node_modules、重新执行firebase init并重装所有依赖,排查一整天仍无进展。

部署命令及报错日志

me@command:~/AndroidStudioProjects/MyDir/functions$ firebase deploy --only functions:eventDates

=== Deploying to 'my-project'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@1.0.0 lint
> eslint --ext .js,.ts .

/bin/sh: 0: Illegal option --

Error: functions predeploy error: Command terminated with non-zero exit code 2

配置文件

firebase.json

{
  "functions": [
    {
      "source": "functions",
      "ignore": [
        "node_modules",
        ".git",
        ".cache",
        "firebase-export*",
        ".vscode",
        ".idea",
        "*.log",
        "*.html",
        "README.md",
        "cache"
      ],
      "predeploy": [
        "npm --prefix \"$RESOURCE_DIR\" run lint",
        "npm --prefix \"$RESOURCE_DIR\" run build"
      ],
      "codebase": "default"
    }
  ],
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "hosting": {
    "public": "build/web",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "storage": {
    "rules": "storage.rules"
  },
  "emulators": {
    "auth": {
      "host": "0.0.0.0",
      "port": 9099
    },
    "functions": {
      "host": "0.0.0.0",
      "port": 5001
    },
    "firestore": {
      "host": "0.0.0.0",
      "port": 8087
    },
    "hosting": {
      "host": "0.0.0.0",
      "port": 5003
    },
    "pubsub": {
      "host": "0.0.0.0",
      "port": 8085
    },
    "storage": {
      "host": "0.0.0.0",
      "port": 9199
    },
    "eventarc": {
      "host": "0.0.0.0",
      "port": 9299
    },
    "ui": {
      "enabled": true
    },
    "singleProjectMode": true
  }
}

package.json

{
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .js,.ts .",
    "build": "tsc",
    "build:watch": "tsc --watch",
    "serve": "npm run build && firebase emulators:start --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "dev": "cd ~/AndroidStudioProjects/MyDir && firebase emulators:start --import=saved-data --export-on-exit && tsc --watch",
    "debug": "cd ~/AndroidStudioProjects/MyDir && firebase emulators:start --import=saved-data --export-on-exit --inspect-functions && tsc --watch",
    "deploy": "cd functions && npm ci && npm run build && cd .. && firebase deploy --only hosting",
    "web": "cd ~/AndroidStudioProjects/MyDir && flutter run -d chrome --web-renderer canvaskit --web-hostname localhost --web-port 45887",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "16"
  },
  "main": "lib/index.js",
  "dependencies": {
    "@aws-sdk/client-s3": "^3.451.0",
    "@google-cloud/pubsub": "^2.15.1",
    "@google-cloud/secret-manager": "^3.7.1",
    "@sendgrid/mail": "^7.6.0",
    "algoliasearch": "^4.10.2",
    "aws-sdk": "^2.1231.0",
    "axios": "^0.27.2",
    "cors": "^2.8.5",
    "eslint": "^8.23.0",
    "express": "^4.18.2",
    "ffmpeg-static": "^4.4.0",
    "firebase-admin": "^11.8.0",
    "firebase-functions": "^4.3.1",
    "lodash": "^4.17.21",
    "luxon": "^1.27.0",
    "node-fetch": "^2.6.7",
    "uuid": "^8.3.2"
  },
  "devDependencies": {
    "@types/ffmpeg-static": "^3.0.0",
    "@types/luxon": "^1.27.0",
    "@types/node-fetch": "^2.6.1",
    "@types/request": "^2.48.7",
    "@types/uuid": "^9.0.0",
    "@typescript-eslint/eslint-plugin": "^5.12.0",
    "@typescript-eslint/parser": "^5.12.0",
    "eslint": "^8.9.0",
    "eslint-config-google": "^0.14.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-import": "^2.25.4",
    "eslint-plugin-prettier": "^4.2.1",
    "firebase-functions-test": "^3.1.0",
    "prettier": "^2.7.1",
    "typescript": "^4.9.0"
  },
  "private": true,
  "version": "1.0.0",
  "author": "",
  "license": "ISC",
  "description": ""
}

解决方案

1. 调整Shell环境兼容性

/bin/sh: 0: Illegal option -- 错误多源于Shell对命令参数的解析差异:

  • 执行 echo $SHELL 确认当前Shell,若为dash(部分系统默认/bin/sh指向dash),可能存在引号解析问题;
  • 临时切换bash执行部署:bash -c "firebase deploy --only functions:eventDates",验证是否正常运行。

2. 修改firebase.json的predeploy命令

移除$RESOURCE_DIR周围的转义引号,Firebase会自动处理路径变量,无需额外转义:

"predeploy": [
  "npm --prefix $RESOURCE_DIR run lint",
  "npm --prefix $RESOURCE_DIR run build"
]

3. 统一ESLint版本

package.json中dependencies和devDependencies同时存在不同版本的eslint(8.23.0和8.9.0),版本冲突可能引发异常:

  • 删除dependencies中的eslint依赖;
  • 重新执行 npm install 安装依赖。

4. 清理Firebase缓存

执行以下命令重置Firebase CLI状态:

rm -rf ~/.cache/firebase
firebase logout && firebase login

5. 本地验证Lint命令

直接在functions目录执行 npm run lint,确认lint命令本身是否能正常运行,排除ESLint配置问题。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 04:07:11