如何使用firebase部署和多个packages.json的功能?

时间:2017-11-21 14:33:08

标签: node.js firebase npm google-cloud-functions

据我了解,firebase函数项目中有两个packages.json文件。一个位于函数目录中,另一个位于项目的顶级目录中。我的packages.json看起来像这样:

功能/ packages.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "dependencies": {
    "express": "^4.16.2",
    "firebase-admin": "~5.4.0",
    "firebase-functions": "^0.7.0",
    "cors": "^2.8.4"
  },
  "private": true,
  "devDependencies": {}
}

packages.json

{
  "name": "a-server",
  "version": "0.0.0",
  "private": true,
  "main": "/functions/index.js",
  "scripts": {
    "clean": "rimraf dist",
    "clean-deploy": "rm -rf functions/node_modules && cp -r node_modules/ functions/node_modules/ && cd functions && npm install",
    "build": "tsc",
    "watch:build": "tsc --watch",
    "lint": "tslint --project tsconfig.json",
    "local-firebase": "firebase serve --only functions,hosting",
    "firebase-deploy": "firebase deploy",
    "start": "npm-run-all clean build lint --parallel watch:build local-firebase",
    "deploy": "npm-run-all clean-deploy build lint firebase-deploy",
    "commit": "git-cz"
  },
  "dependencies": {
    "aws-sdk": "^2.138.0",
    "fs": "0.0.1-security",
    "http-status-codes": "^1.3.0",
    "inversify": "^4.4.0",
    "jwt-simple": "^0.5.1",
    "moment": "^2.19.1",
    "reflect-metadata": "^0.1.10",
    "request": "^2.81.0",
    "request-promise": "^4.2.1"
  },
  "devDependencies": {
    "@types/bluebird": "^3.5.16",
    "@types/jwt-simple": "^0.5.33",
    "@types/node": "^8.0.46",
    "@types/request-promise": "^4.1.38",
    "bluebird": "^3.5.1",
    "body-parser": "^1.18.2",
    "commitizen": "^2.9.6",
    "nodemon": "^1.12.1",
    "npm-run-all": "^4.1.1",
    "rimraf": "^2.6.2",
    "ts-node": "^3.3.0",
    "typescript": "^2.5.3"
  },
  "exclude": [
    "**/node_modules/**/*"
  ]
}

起初我认为我能做的就是在顶级目录下的packages.json中设置一个类似deploy所示的脚本;意图是我将所有node_modules复制到函数目录,cd进入它,然后安装它的包。但是,firebase部署无法识别root packages.json中的依赖项并返回:

i  deploying functions, hosting
i  functions: ensuring necessary APIs are enabled...
i  runtimeconfig: ensuring necessary APIs are enabled...
✔  runtimeconfig: all necessary APIs are enabled
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...

Error: Error parsing triggers: Cannot find module 'http-status-codes'

如何让函数package.json识别出顶级packages.json中存在依赖关系?或者我应该将所有这些依赖项移到functions/packages.json

0 个答案:

没有答案