firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Error: functions/index.js does not exist, can't deploy Firebase Functions

Open dfischer opened this issue 8 years ago • 31 comments

Version info

3.17.3

Steps to reproduce

Setup a new typescript project

Run npm run build

Expected behavior

It deploys and uses the file from lib/index.js (which it isn't) declared in package.json under main

Actual behavior

npm run deploy --debug

> @ deploy XXX/functions
> firebase deploy --only functions


=== Deploying to 'XXX-XXXX'...

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

> @ build /XXX/functions
> tsc

✔  functions: Finished running predeploy script.

Error: functions/index.js does not exist, can't deploy Firebase Functions
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ deploy: `firebase deploy --only functions`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/DFischer/.npm/_logs/2018-01-24T15_28_36_051Z-debug.log```

dfischer avatar Jan 24 '18 15:01 dfischer

Can you share your package.json file?

tinaliang avatar Jan 24 '18 21:01 tinaliang

  "name": "functions",
  "scripts": {
    "test": "jest",
    "build": "./node_modules/.bin/tsc",
    "serve": "npm run build && firebase serve --only functions",
    "shell": "npm run build && firebase experimental:functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "jest": {
    "transform": {
      "^.+\\.tsx?$": "ts-jest"
    },
    "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx",
      "json"
    ]
  },
  "dependencies": {
    "@types/axios": "^0.14.0",
    "@types/lodash": "^4.14.92",
    "@types/node": "^8.0.53",
    "axios": "^0.17.1",
    "body-parser": "^1.17.2",
    "firebase-admin": "^5.0.0",
    "firebase-functions": "^0.8.1",
    "lodash": "^4.17.4",
    "pipedrive": "^3.0.2",
    "sendgrid": "^5.2.0",
    "smooch-core": "^5.6.0",
    "string-tokenizer": "^0.0.8"
  },
  "devDependencies": {
    "@types/express": "^4.11.0",
    "@types/jest": "^22.1.0",
    "jest": "^22.1.4",
    "ts-jest": "^21.2.3",
    "tslint": "^5.9.1",
    "typescript": "^2.6.1"
  },
  "private": true,
  "main": "lib/index.js"
}

dfischer avatar Jan 25 '18 07:01 dfischer

@dfischer Can you run the command again with the --debug flag, and paste the output here? As well, where is your package.json located?

laurenzlong avatar Jan 25 '18 18:01 laurenzlong

package.json is located in ./functions/package.json

npm run deploy --debug

> @ deploy /Users/DFischer/Code/X/X/functions
> firebase deploy --only functions


=== Deploying to 'X-XXX'...

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

> @ build /Users/DFischer/Code/X/X/functions
> tsc

✔  functions: Finished running predeploy script.

Error: functions/index.js does not exist, can't deploy Firebase Functions
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ deploy: `firebase deploy --only functions`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/DFischer/.npm/_logs/2018-01-24T15_28_36_051Z-debug.log

dfischer avatar Jan 26 '18 04:01 dfischer

That's interesting...the package.json content should have been printed in the console with the debug command.

Unfortunately, I was unable to reproduce this exact error. As a last resort (if you want), can you try npm uninstall -g firebase-tools && npm i -g firebase-tools and reinitializing your project?

tinaliang avatar Jan 26 '18 19:01 tinaliang

@tinaliang Should I reinitialize in the root directory /project/ or /project/functions/ ?

dfischer avatar Jan 29 '18 04:01 dfischer

Try changing the deploy command in your package.json to firebase deploy --only functions --debug and then show us the results. That should help us understand what the CLI is seeing before it fails.

mbleigh avatar Jan 29 '18 05:01 mbleigh

@dfischer reinitialize in /project/

tinaliang avatar Jan 29 '18 19:01 tinaliang

thank you for all your hard work @tinaliang

annie avatar Feb 01 '18 06:02 annie

great work firebase team! great quick responses @tinaliang!

eunicekokor avatar Feb 01 '18 06:02 eunicekokor

I have the same issue on v3.17.4
Reinstalling firebase-tools and reinitializing the project doesn't help. Here is the output of $ firebase deploy --only functions --debug:

$ firebase deploy --only functions --debug
[2018-02-02T08:42:11.096Z] ----------------------------------------------------------------------
[2018-02-02T08:42:11.101Z] Command:       /home/dan/.nvm/versions/node/v6.11.5/bin/node /home/dan/.nvm/versions/node/v6.11.5/bin/firebase deploy --only functions --debug
[2018-02-02T08:42:11.102Z] CLI Version:   3.17.4
[2018-02-02T08:42:11.103Z] Platform:      linux
[2018-02-02T08:42:11.103Z] Node Version:  v6.11.5
[2018-02-02T08:42:11.104Z] Time:          Fri Feb 02 2018 11:42:11 GMT+0300 (STD)
[2018-02-02T08:42:11.107Z] ----------------------------------------------------------------------

[2018-02-02T08:42:11.128Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2018-02-02T08:42:11.129Z] > authorizing via signed-in user
[2018-02-02T08:42:11.133Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects/anyconf-a

 Fri Feb 02 2018 11:42:11 GMT+0300 (STD)
[2018-02-02T08:42:11.950Z] <<< HTTP RESPONSE 200 server=nginx, date=Fri, 02 Feb 2018 08:42:12 GMT, content-type=application/json; charset=utf-8, content-length=100, connection=close, x-content-type-options=nosniff, strict-transport-security=max-age=31536000; includeSubdomains, cache-control=no-cache, no-store
[2018-02-02T08:42:11.953Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/database/anyconf-a/tokens

 Fri Feb 02 2018 11:42:11 GMT+0300 (STD)
[2018-02-02T08:42:12.612Z] <<< HTTP RESPONSE 200 server=nginx, date=Fri, 02 Feb 2018 08:42:13 GMT, content-type=application/json; charset=utf-8, content-length=256, connection=close, x-content-type-options=nosniff, strict-transport-security=max-age=31536000; includeSubdomains, cache-control=no-cache, no-store

=== Deploying to 'anyconf-a'...

i  deploying functions
Running command: npm --prefix functions run build

> functions@ build /mnt/c/Users/User/Projects/junto/anyconf/anyconf-cloud-functions/functions
> tslint -p tslint.json && ./node_modules/.bin/tsc

✔  functions: Finished running predeploy script.
[2018-02-02T08:42:19.412Z] > [functions] package.json contents: {
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase serve --only functions",
    "shell": "firebase experimental:functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log",
    "build": "./node_modules/.bin/tslint -p tslint.json && ./node_modules/.bin/tsc"
  },
  "dependencies": {
    "@types/cookie-parser": "^1.4.1",
    "@types/cors": "^2.8.3",
    "@types/express": "^4.11.1",
    "cookie-parser": "^1.4.3",
    "cors": "^2.8.4",
    "express": "^4.16.2",
    "firebase": "^4.9.0",
    "firebase-admin": "^5.8.1",
    "firebase-functions": "^0.8.1",
    "firestore": "^1.1.6",
    "typescript": "^2.7.1"
  },
  "private": true,
  "devDependencies": {
    "tslint": "^5.9.1"
  }
}

Error: functions/index.js does not exist, can't deploy Firebase Functions

daniil-konovalenko avatar Feb 02 '18 08:02 daniil-konovalenko

@daniil-konovalenko You're missing the "main" field in your package.json. Please add "main": "lib/index.js" to your package.json.

tinaliang avatar Feb 02 '18 18:02 tinaliang

@tinaliang it works now, thank you!

daniil-konovalenko avatar Feb 03 '18 08:02 daniil-konovalenko

Not sure what happened but reinitializing from scratch fixed it. I'm good, thanks :)

dfischer avatar Feb 05 '18 15:02 dfischer

I speak Spanish, which is referred to "reinitializing the project"

alemarcano avatar Apr 03 '18 05:04 alemarcano

i have the same error in deploy index.js does not exist ... and i have the " main " in package.json

Abeer-h avatar Jun 02 '18 13:06 Abeer-h

i am getting this error 👎

        mode.

[17:07:09] console.error: [2018-06-13T12:07:09.305Z] @firebase/firestore: Firestore (5.0.4): The behavior for Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK. To hide this warning and ensure your app does not break, you need to add the following code to your app before calling any other Cloud Firestore methods: const firestore = firebase.firestore(); const settings = {/* your settings... */ timestampsInSnapshots: true}; firestore.settings(settings); With this change, timestamps stored in Cloud Firestore will be read back as Firebase Timestamp objects instead of as system Date objects. So you will also need to update code expecting a Date to instead expect a Timestamp. For example: // Old: const date = snapshot.get('created_at'); // New: const timestamp = snapshot.get('created_at'); const date = timestamp.toDate(); Please audit all existing usages of Date when you enable the new behavior. In a future release, the behavior will change to the new behavior, so if you do not follow these steps, YOUR APP MAY BREAK.

SamiHK avatar Jun 13 '18 12:06 SamiHK

@Sami-Haroon-Khan This is a warning from the firebase module, due to a change in behavior of Firestore timestamp values. You shouldn't need to use firebase in your functions. I recommend using firebase-admin to access Firestore. Since it is already a peer dependency of firebase-functions, this will make your overall package smaller.

laurenzlong avatar Jun 13 '18 23:06 laurenzlong

If you do want to continue using firebase, then follow the instructions in the message to suppress the warning.

laurenzlong avatar Jun 13 '18 23:06 laurenzlong

@laurenzlong Yes, I fixed it by following the instructions. Thanks.

SamiHK avatar Jun 14 '18 05:06 SamiHK