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

Firebase云函数编译报错:私有标识符仅支持ES2015及更高版本

问题:TypeScript转译时出现私有标识符兼容错误

问题场景

执行以下命令将index.ts转译为index.js:

tsc index.ts

触发如下错误:

../node_modules/@google-cloud/storage/build/src/crc32c.d.ts:68:5 - error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher.

68     #private;
~~~~~~~~
../node_modules/@google-cloud/storage/build/src/file.d.ts:253:5 - error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher.

253     #private;
~~~~~~~~
../node_modules/@google-cloud/storage/build/src/hash-stream-validator.d.ts:11:5 - error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher.

11     #private;

已尝试的无效方案

已知将tsconfig.json中的target设置为es2017可解决此类私有标识符兼容问题,但配置后错误仍存在。当前tsconfig.json内容如下:

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
    "downlevelIteration": true,
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

尝试过多种配置变体均无效,该问题在升级firebase-admin到^11.3.0版本后首次出现,推测可能需要更新其他依赖包来解决。

项目依赖配置(package.json)

{
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .ts .",
    "build": "tsc",
    "serve": "npm run build && firebase emulators:start --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "test": "mocha --reporter spec --timeout 10000",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "14"
  },
  "main": "lib/index.js",
  "dependencies": {
    "@babel/core": "^7.2.0",
    "@babel/preset-env": "^7.2.0",
    "@babel/runtime": "^7.2.0",
    "@firebase/app-compat": "^0.1.28",
    "@types/rimraf": "^3.0.2",
    "axios": "^0.27.2",
    "chai": "^4.3.4",
    "csv-parse": "^5.2.1",
    "firebase-admin": "^11.3.0",
    "firebase-functions": "^4.1.0",
    "fs": "0.0.1-security",
    "mocha": "^9.1.3",
    "puppeteer": "^10.4.0",
    "rimraf": "^3.0.2",
    "typescript": "4.3.5",
    "typesense": "^1.3.0"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^4.33.0",
    "@typescript-eslint/parser": "^4.33.0",
    "eslint": "^7.6.0",
    "eslint-config-google": "^0.14.0",
    "eslint-plugin-import": "^2.22.0",
    "firebase-functions-test": "^0.3.3"
  },
  "private": true
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 14:55:19