3.17.3
Setup a new typescript project
Run npm run build
It deploys and uses the file from lib/index.js (which it isn't) declared in package.json under main
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```
Can you share your package.json file?
{
"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 Can you run the command again with the --debug flag, and paste the output here? As well, where is your package.json located?
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
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 Should I reinitialize in the root directory /project/ or /project/functions/ ?
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.
@dfischer reinitialize in /project/
thank you for all your hard work @tinaliang
great work firebase team! great quick responses @tinaliang!
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 You're missing the "main" field in your package.json. Please add "main": "lib/index.js" to your package.json.
@tinaliang it works now, thank you!
Not sure what happened but reinitializing from scratch fixed it. I'm good, thanks :)
I speak Spanish, which is referred to "reinitializing the project"
i have the same error in deploy
index.js does not exist ...
and i have the " main " in package.json
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.
@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.
If you do want to continue using firebase, then follow the instructions in the message to suppress the warning.
@laurenzlong Yes, I fixed it by following the instructions. Thanks.
Delete a functions folder if you have one.
Had this issue with Google Functions not being deployed. Make sure the directory containing the file is not ignored in .gcloudignore file:
#!include:.gitignore
# HERE
!functions
solved by setting "main" in package.json to:
"main": "lib/functions/src/index.js"
@turnono es la solución mas exacta en mi caso, I fixed it
Most helpful comment
@daniil-konovalenko You're missing the "main" field in your package.json. Please add
"main": "lib/index.js"to your package.json.