0
votes

When I try deploying my Firebase cloud functions I get the following error.

Desired behavior: Deploy functions successfully.

Error:

Error: There was an error reading functions/package.json:

functions/lib/index.js does not exist, can't deploy Cloud Functions

Full log:

name@name-MacBook-Pro functions % firebase deploy

=== Deploying to 'newtiktok-21570'...

i deploying functions Running command: npm --prefix "$RESOURCE_DIR" run lint

functions@ lint /Users/name/Desktop/Yoveo/functions eslint "src/**/*"

/Users/name/Desktop/Yoveo/functions/src/index.ts
186:67 warning 'timestamp' is defined but never used
@typescript-eslint/no-unused-vars 377:86 warning 'mediaNum' is defined but never used @typescript-eslint/no-unused-vars 377:104 warning 'commentText' is defined but never used @typescript-eslint/no-unused-vars 377:125 warning 'commentID' is defined but never used @typescript-eslint/no-unused-vars 419:119 warning 'commentID' is defined but never used
@typescript-eslint/no-unused-vars 463:121 warning 'commentID' is defined but never used @typescript-eslint/no-unused-vars 520:75
warning 'mediaNum' is defined but never used
@typescript-eslint/no-unused-vars 732:25 warning 'slap' is defined but never used @typescript-eslint/no-unused-vars

✖ 8 problems (0 errors, 8 warnings)

Running command: npm --prefix "$RESOURCE_DIR" run build ✔ functions: Finished running predeploy script.

Error: There was an error reading functions/package.json:

My p.json:

 {
  "name": "functions",
  "scripts": {
    "lint": "eslint \"src/**/*\"",
    "build": "",
    "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": "12"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "^9.2.0",
    "firebase-functions": "^3.11.0"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^4.8.1",
    "@typescript-eslint/parser": "^4.8.1",
    "eslint": "^7.14.0",
    "eslint-plugin-import": "^2.22.0",
    "firebase-functions-test": "^0.2.0",
    "typescript": "^3.8.0"
  },
  "private": true
}
3
Please have a look into this Official Documentation. Please execute npm install from functions folder and deploy again. Could you please share your directory structure? Please also have a look into the Firebase Official Documentation.Nibrass H

3 Answers

1
votes

For some reason recently the build flow of firebase functions changed.

It used to be:

npm --prefix ./functions install ./functions
firebase deploy --only functions

now it is:

npm --prefix ./functions install ./functions
npm --prefix ./functions run build
firebase deploy --only functions

I have not researched what caused this change, but adding this as build step fixed the problem for me.

0
votes

Solved:

I was able to solve the problem by removing everything associated with Firebase functions. And running: firebase init again. After I cd functions run npm install. Then I was able to deploy successfully after fixing an error with:

    3:26  error    'express' should be listed in the project's dependencies. Run 'npm i -S express' to add it  import/no-extraneous-dependencies
0
votes

functions/lib/index.js does not exist

In case you are working in firebase project that contains a frontend or is structured as a monorepo, this error may also stem from having accidentally imported a frontend file in the functions backend part of the project. Since those files are not within your funcions project scope, the typescript compiler will not compile ts files referencing them. So in this case, the solution is to search for any imports containing /src/ (or any other paths pointing outside) and remove them within your functions project.