"firebase serve --only functions" 无效

"firebase serve --only functions" doesn't work

$ firebase serve --only functions
⚠  Your requested "node" version "8" doesn't match your global version "12" 
Error: TIMEOUT: Port 5000 was not active within 30000ms

但是服务托管会成功

$ firebase serve --only hosting
i  hosting: Serving hosting files from: dist/chongsheng-jp
✔  hosting: Local server: http://localhost:5000

我以为我没有编译 index.ts,我按照 firebase 官方文档尝试了 npm run serve 但它不起作用。

请帮助我。

这是我的版本。

"firebase-admin": "^8.0.0",
"firebase-functions": "^3.1.0"

node -v
v12.3.1

firebase --version
7.1.0

我在 WSL(不是 wsl2)上使用 ubuntu,版本低于

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:        18.04
Codename:       bionic

这是我的代码 (index.ts)

const functions = require('firebase-functions');

// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions

exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send("Hello from Firebase!");
});

参见 https://firebase.google.com/docs/functions/manage-functions#set_nodejs_version

Your requested "node" version "8" doesn't match your global version "12"

您应该使用 Node.js 8 或 Node.js 10。而不是 Node.js 12.

首先,检查您的节点版本,您可以像 nvm 一样使用节点版本管理器管理节点版本。

我只是在新项目和现有项目上看到同样的问题。它与节点版本、正在使用的端口或项目代码无关。恢复到以前的版本对我有用:

npm i -g firebase-tools@7.0.2

v7.1.0 版本中的某些内容一定是导致此问题的原因。