NodeJS 部署firebase函数-生成失败:npm错误!无法读取未定义的属性“body-parser”

tct7dpnv  于 2023-08-04  发布在  Node.js
关注(0)|答案(1)|浏览(96)

我在尝试将一个函数部署到firebase时遇到了一个问题。
构建失败:npm错误!无法读取undefined`的属性'body-parser'。
我在使用node版本18时没有得到错误:

...
"engines": {
      "node": "18"
 },
...

字符串
但是,我需要使用节点版本14,因为我正在连接到旧版本的MSSQL。
package.json

{
      "name": "functions",
      "scripts": {
        "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",
        "deploy": "firebase deploy --only functions",
        "logs": "firebase functions:log"
      },
      "engines": {
          "node": "14"
      },
      "main": "lib/index.js",
      "dependencies": {
        "body-parser": "^1.20.2",
        "cors": "^2.8.5",
        "express": "^4.18.2",
        "mssql": "^9.1.1",
        "short-uuid": "^4.2.2",
        "firebase-admin": "^11.5.0",
        "firebase-functions": "^4.2.0"
      },
      "devDependencies": {
        "@types/mssql": "^8.1.2",
        "@types/cors": "^2.8.13",
        "@types/express": "^4.17.17",
        "@types/node": "^20.4.5",
        "@types/body-parser": "^1.19.2",
        "concurrently": "^8.2.0",
        "nodemon": "^3.0.1",
        "typescript": "^4.5.4",
        "firebase-functions-test": "^3.0.0"
      },
      "private": true
    }


firebase.json

...
"functions": [
    {
      "source": "functions",
      "codebase": "default",
      "ignore": [
        "node_modules",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ],
      "predeploy": [
        "npm --prefix \"$RESOURCE_DIR\" run build"
      ]
    }
  ],
...


tsconfig.json

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


如何才能使用版本14进行部署?

ha5z0ras

ha5z0ras1#

我删除了package-lock.json,它工作了。

相关问题