Deploying Firebase functions with a shared package shows errors about conflicting lockfiles - firebase

I am working off a monorepo with folders
/front
/back
/shared
I am trying to deploy my backend functions to Firebase.
I can run them on Firebase emulator nicely locally. However, when trying to deploy them online, I am faced with this error:
...
i deploying functions
i functions: preparing codebase default for deployment
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔ functions: required API cloudfunctions.googleapis.com is enabled
✔ functions: required API cloudbuild.googleapis.com is enabled
✔ artifactregistry: required API artifactregistry.googleapis.com is enabled
i functions: Loaded environment variables from .env.
i functions: preparing functions directory for uploading...
i functions: packaged $PROJECT_PATH/MYPROJECT/back/functions (2.39 MB) for uploading
✔ functions: functions folder uploaded successfully
i functions: creating Node.js 18 function api(us-central1)...
Build failed: npm ERR! code EUSAGE
npm ERR!
npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
npm ERR!
npm ERR! Invalid: lock file's #MYPROJECT/shared#1.0.0 does not satisfy #MYPROJECT/shared#
npm ERR! Missing: #MYPROJECT/shared# from lock file
npm ERR!
npm ERR! Clean install a project
npm ERR!
npm ERR! Usage:
npm ERR! npm ci
npm ERR!
...
In back/functions/package.json, I have this:
"dependencies": {
"#MYPROJECT/shared": "file:../../shared",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"firebase-admin": "^11.5.0",
"firebase-functions": "^4.2.1",
"got": "^11.8.2",
"openai": "^2.0.5",
"serialize-error": "^11.0.0",
"vite": "^4.0.4",
"vitest": "^0.28.3"
},
And in shared/package.json
"devDependencies": {
"#types/jest": "^29.1.2",
"#types/node": "^18.8.5",
"#typescript-eslint/eslint-plugin": "^5.38.0",
"#typescript-eslint/parser": "^5.38.0",
"#vitest/coverage-c8": "^0.28.3",
"eslint": "^8.23.1",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.7.1",
"typescript": "^4.8.4",
"vite": "^4.0.4",
"vitest": "^0.28.3"
}
}
In back/firebase.json I have this:
{
"source": "functions",
"functions": {
"predeploy": "npm --prefix functions run build"
}
}
I tried reinstalling everything like this:
cd $PROJECT_PATH/MYPROJECT/shared
rm -r node_modules; rm package-lock.json; npm cache clean --force
cd $PROJECT_PATH/MYPROJECT/back/functions
rm -r node_modules; rm package-lock.json; npm cache clean --force
npm install
cd $PROJECT_PATH/MYPROJECT/shared
npm install
cd $PROJECT_PATH/MYPROJECT/back/
firebase functions:delete api; firebase deploy --only functions
But I still get the same error.
Any other suggestions on what could be the issue?

Related

How do deploy a firebase cloud function that depends on a private package?

I have a local private npm package with common types. My web application imports the common package no problem.
firebase deploy fails when I try adding the common package to my cloud functions package.
I added the dependency to functions/package.json like this:
"dependencies": {
"#google-cloud/pubsub": "^2.16.1",
"firebase-admin": "^9.2.0",
"firebase-functions": "^3.11.0",
"shared-types": "file:../shared-types",
"uuid": "^8.3.2"
},
npm run build and npm run lint pass locally, but firebase deploy fails:
% firebase deploy --only functions:submitEndorsement
=== Deploying to '<redacted>'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions# lint /Users/jeff/gitrepos/code/code/<redacted>/functions
> eslint --ext .js,.ts .
Running command: npm --prefix "$RESOURCE_DIR" run build
> functions# build /<redacted>/functions
> tsc
✔ functions: Finished running predeploy script.
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 functions directory for uploading...
i functions: packaged functions (156.21 KB) for uploading
✔ functions: functions folder uploaded successfully
i functions: current functions in project: <redacted>
i functions: uploading functions in project: submitEndorsement(us-central1)
i functions: updating Node.js 12 function submitEndorsement(us-central1)...
✔ scheduler: required API cloudscheduler.googleapis.com is enabled
⚠ functions[submitEndorsement(us-central1)]: Deployment error.
Build failed: npm ERR! code EEXIST
npm ERR! syscall mkdir
npm ERR! path /workspace/node_modules/shared-types
npm ERR! errno -17
npm ERR! EEXIST: file already exists, mkdir '/workspace/node_modules/shared-types'
npm ERR! File exists: /workspace/node_modules/shared-types
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
npm ERR! A complete log of this run can be found in:
npm ERR! /www-data-home/.npm/_logs/2021-07-27T23_06_20_742Z-debug.log; Error ID: beaf8772
Functions deploy had errors with the following functions:
submitEndorsement
To try redeploying those functions, run:
firebase deploy --only "functions:submitEndorsement"
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.

npm ERR! peer dep missing: firebase-admin#^7.0.0, required by firebase-functions#2.3.1

I am trying to understand how to get the version of firebase-admin that is required. My scenario is this:
MYPATH\functions>npm list firebase-admin
functions# MYPATH\functions
`-- UNMET PEER DEPENDENCY firebase-admin#6.5.1
npm ERR! peer dep missing: firebase-admin#^7.0.0, required by firebase-functions#2.3.1
Running npm update firebase-admin does not change anything.
package.json contains this line:
"dependencies": {
...
"firebase-admin": "^6.5.1",
What am I supposed to do?
UPDATE:
When doing firebase serve I get this error:
! Your requested "node" version "6" doesn't match your global version "10"
....
+ hosting: Local server: http://localhost:5000
! The Cloud Functions emulator requires the module "firebase-admin" to be installed. This package is in your package.json, but it's not available. You probably need to run "npm install" in your functions directory.
i functions: Your functions could not be parsed due to an issue with your node_modules (see above)
'npm update' is working, however the '^' carat against "firebase-admin" in your package.json will limit the updates to the 6.x releases - so it's not getting anything newer then the 6.5.1 release.
You can manually change the version of "firebase-admin" in your package.json to "^7.0.0" and then run 'npm install'. This will grab the latest release in the 7.x.x range.

What's the reason for NPM Error on firebase deploy --only functions

I am recently getting this error when attempting to deploy my firebase functions. However, I didn't change any dependencies since last successful deploy...
✔ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (57.25 KB) for uploading
✔ functions: functions folder uploaded successfully
i functions: updating Node.js 6 function firestoreEmail(us-central1)...
i functions: updating Node.js 6 function apiMain(us-central1)...
✔ functions[apiMain(us-central1)]: Successful update operation.
⚠ functions[firestoreEmail(us-central1)]: Deployment error.
Build failed: exit status 1
npm ERR! Linux 4.4.0-133-generic
npm ERR! argv "/nodejs/bin/node" "/nodejs/bin/npm" "--global-style" "--production" "--fetch-retries=5" "--fetch-retry-factor=2" "--fetch-retry-mintimeout=1000" "install" "/workspace"
npm ERR! node v6.14.0
npm ERR! npm v3.10.10
npm ERR! Hostname/IP doesn't match certificate's altnames: "Host: registry.npmjs.org. is not in the cert's altnames: DNS:a.sni.fastly.net, DNS:a.sni.global-ssl.fastly.net"
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /workspace/npm-debug.log
Functions deploy had errors. To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
Firebase status page mentions that there is an NPM registry outage
https://status.firebase.google.com/incident/Functions/18033
There has been an outage https://status.npmjs.org/incidents/v22ffls5cd6h - they recommend changing your DNS as ISP's are caching the wrong details.
Run this line(I know it's ugly, but it works):
dig www.npmjs.com #1.1.1.1 | tac | echo "$(grep -oP 'www\.npmjs\.com(.)+\t\K([\d\.]*)' -m 1) www.npmjs.com"
Copy and paste the output to the end of /etc/hosts file

error code ELIFECYCLE errno 1 error functions# lint: `eslint .` while deploying firebase [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
i am trying to deploy my function to the firebase but when ever i execute
firebase deploy
i do get the error.
C:\Users\vimiv>firebase deploy
=== Deploying to 'touch-keeper'...
i deploying functions, hosting
Running command: npm --prefix "%RESOURCE_DIR%" run lint
> functions# lint C:\Users\vimiv\functions
> eslint .
module.js:549
throw err;
^
Error: Cannot find module 'wordwrap'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\vimiv\functions\node_modules\optionator\lib\help.js:6:14)
at Object.<anonymous> (C:\Users\vimiv\functions\node_modules\optionator\lib\help.js:247:4)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions# lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions# lint 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! C:\Users\vimiv\AppData\Roaming\npm-cache\_logs\2018-08-
17T10_47_41_587Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code1
here is my index.js
'use-strict'
const admin = require('firebase-admin');
const functions = require('firebase-functions');
admin.initializeApp(functions.config().firebase);
exports.sendMessageNotification = functions.database.ref('DR/MELTING/{itemname}').onWrite(event => {
//const itemname = event.params.itemname;
console.log("Notificatiion Triggered Successfuly");
});
here is my package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "^6.0.0",
"firebase-functions": "^2.0.5",
"prelude-ls": "^1.1.2",
"word-wrap": "^1.2.3"
},
"devDependencies": {
"eslint": "^4.12.0",
"eslint-plugin-promise": "^3.6.0"
},
"private": true
}
And also i changed my firebase.json prefix command
You need to install any dependency you may be using in your function. Run npm install inside your functions folder.
Try with npm install -g word-wrap and after firebase deploy.

How to resolve this error when deploying on firebase

I'm trying to deploy a function to Firebase, using the command:
firebase deploy --only functions
Here is the Package.json file:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "~5.12.1",
"firebase-functions": "^1.0.3"
},
"devDependencies": {
"eslint": "^4.12.0",
"eslint-plugin-promise": "^3.6.0"
},
"private": true
}
I copied the error from my node.js file, Now I'm having this error:
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
npm ERR! path C:\Users\Pc1\Desktop\TimeCard\TimeCardA\src\app\index\firecast\%RESOURCE_DIR%\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\Pc1\Desktop\TimeCard\TimeCardA\src\app\index\firecast\%RESOURCE_DIR%\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Pc1\AppData\Roaming\npm-cache_logs\2018-07-23T03_23_10_348Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code4294963238
C:\Users\Pc1\Desktop\TimeCard\TimeCardA\src\app\index\firecast>npm run deploy
npm ERR! missing script: deploy
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Pc1\AppData\Roaming\npm-cache\_logs\2018-07-23T03_33_19_115Z-debug.log

Resources