1

I'm having a difficulty deploying Firebase functions from CI (namely AWS CodeBuild) due to unknown reasons.

The firebase deploy command is invoked with --token argument, so it doesn't seem like an authentication issue, in fact, hosting files are being deployed without any issues.

One suspicion I have is that when I run this locally, it works like a charm, and the obvious difference is the part that says package . (263 B) for uploading because when I run it locally, it has way more than 263-bytes (local says 69.23 MB). Also, because it runs locally without any issues, I don't think there is any issue with firebase.json is configured incorrectly.

Has anyone ran into a similar issue?

$ export DOTENV_RUNTIME=qa1 && cross-env NODE_ENV=production firebase deploy --only hosting,functions --token $FIREBASE_TOKEN

...
i  deploying functions, hosting
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
i  functions: preparing . directory for uploading...
i  functions: packaged . (263 B) for uploading
✔  functions: . folder uploaded successfully
i  hosting[project-xyz]: beginning deploy...
i  hosting[project-xyz]: found 47 files in public
✔  hosting[project-xyz]: file upload complete
i  functions: updating Node.js 12 function nextServer(us-central1)...
⚠  functions[nextServer(us-central1)]: Deployment error.
Build failed: function.js does not exist; Error ID: 7485c5b6


Functions deploy had errors with the following functions:
    nextServer


To try redeploying those functions, run:
    firebase deploy --only "functions:nextServer"


To continue deploying other features (such as database), run:
    firebase deploy --except functions

Error: Functions did not deploy properly.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Here are the contents of some of the relevant configuration files:

firebase.json

{
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "**",
        "function": "nextServer"
      }
    ]
  },
  "functions": {
    "source": ".",
    "ignore": [
      ".git/**",
      ".firebase/**",
      ".firebaserc",
      "**/node_modules/**",
      "**/public/**",
      "**/src/**"
    ]
  }
}

package.json

{
  ...
  "main": "dist/server/index.js",
  "engines": {
    "node": "12"
  },
  ...
}
Here's the root directory structure.
$ tree -v -L 1 -a
.
├── .firebase
├── .firebaserc
├── .git
├── .gitignore
├── README.md
├── dist
├── firebase.json
├── node_modules
├── package.json
├── public
├── src
└── yarn.lock
4
  • Can you share what your project root directory looks like? Commented Feb 12, 2021 at 3:41
  • @nVitius Thanks for your comment. Added the root directory structure. Commented Feb 12, 2021 at 13:26
  • Where do you define your functions? Your firebase config is set up to use . directory for the functions, but there is no index.js. I believe this might be causing the issue. Commented Feb 12, 2021 at 20:58
  • @nVitius Thanks for your comment. The functions are defined in dist/server/index.js as specified in package.json's main directive. Given your input, I've tried relocating index.js to the root, but no difference made and packaged size still seems to be very small. Besides, I think deploy is picking up that file without issues as the log mentions it: updating Node.js 12 function nextServer(us-central1). ( nextServer is one of the functions declared in dist/server/index.js) Commented Feb 13, 2021 at 21:12

1 Answer 1

1

I went through the firebase-tools source code and found that when using AWS Code Build, the source is downloaded and built under /codebuild/output/src123456789/src/github.com/.... If you ignore **/src/**, no files would be targeted for deploy because the path name contains src. This also answers why the packaged size was so small.

Thanks to @nVitius for raising questions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.