Firebase login throws Error: spawn cmd ENOENT in NodeJS - node.js

I am trying to set up my Firebase TypeScript application on another system. When I execute firebase login, it throws the following exception:
[debug] [2020-07-10T12:35:28.031Z] ----------------------------------------------------------------------
[debug] [2020-07-10T12:35:28.034Z] Command: C:\Program Files\nodejs\node.exe C:\Users\gp\AppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js login
[debug] [2020-07-10T12:35:28.034Z] CLI Version: 8.5.0
[debug] [2020-07-10T12:35:28.034Z] Platform: win32
[debug] [2020-07-10T12:35:28.035Z] Node Version: v12.18.2
[debug] [2020-07-10T12:35:28.036Z] Time: Fri Jul 10 2020 18:05:28 GMT+0530 (India Standard Time)
[debug] [2020-07-10T12:35:28.036Z] ----------------------------------------------------------------------
[debug] [2020-07-10T12:35:28.037Z]
[info] i Firebase optionally collects CLI usage and error reporting information to help improve our products. Data is collected in accordance with Google's privacy policy (https://policies.google.com/privacy) and is not used to identify you.
[info] i To change your data collection preference at any time, run `firebase logout` and log in again.
[info]
[info] Visit this URL on this device to log in:
[info] https://accounts.google.com/o/oauth2/auth?client_id=563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com&scope=email%20openid%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloudplatformprojects.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Ffirebase%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&response_type=code&state=3839&redirect_uri=http%3A%2F%2Flocalhost%3A
[info]
[info] Waiting for authentication...
[debug] [2020-07-10T12:57:25.170Z] Error: spawn cmd ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
[error]
[error] Error: An unexpected error has occurred.
On the new system, I am using the following software:
node v12.18.2
npm v6.14.5
On the old system, I was using the following software:
node v10.16.3
npm v6.12.0
I have also tried the following:
executing npm install -g firebase-tools#latest
executing all steps in a separate cmd running as admin.
Everything was working perfectly in my old workspace.

Fixed the issue by adding 'C:\Windows\System32' in my environment variable.

Related

Jenkins with Maven and npm process fails with EAGAIN error during npm install

So i got my jenkins pipeline setup for a application that uses spring boot as backend and vuejs as frontend. The maven build process builds the frontend first, copies that to the backend and then builds the backend. But during the build of the frontend the process fails ONLY if i run it through the jenkins pipeline. (for other people the same pipeline apparently works on a different machine)
[INFO] npm ERR! code EAGAIN
[INFO] npm ERR! syscall spawn sh
[INFO] npm ERR! path /var/lib/jenkins/workspace/pipeline/frontend/node_modules/pre-commit
[INFO] npm ERR! errno -11
[INFO] npm ERR! spawn sh EAGAIN
[INFO] npm ERR! command sh -c node install.js
[INFO]
[INFO] npm ERR! A complete log of this run can be found in:
[INFO] npm ERR! /var/lib/jenkins/.npm/_logs/2022-07-22T09_11_43_478Z-debug-0.log
the relevant part of the log is here: https://pastebin.com/ewp6zRcv
the jenkins pipeline is:
pipeline {
agent any
parameters {
gitParameter branchFilter: 'origin/(.*)', defaultValue: 'staging', name: 'BRANCH', type: 'PT_BRANCH'
}
tools {
maven "Maven"
nodejs "Node"
}
stages {
stage('Build') {
steps {
// Get some code from a GitHub repository
git branch: "${params.BRANCH}", url: 'https://github.com/TheExkaliburg/MoreFair'
// Run Maven on a Unix agent.
sh "mvn -Dmaven.test.failure.ignore=true clean package"
}
post {
success {
archiveArtifacts 'target/*.jar'
}
}
}
}
}
the jenkins is installed on a linux server with ubuntu 20.04 and the project itself can be found on https://github.com/TheExkaliburg/MoreFair and the branch to be built is staging
the strange thing is that EAGAIN failures are normally “Resource temporarily unavailable.” failures. running the process as root or as the jenkins user works fine without any errors, i have enough leftover disk space and my ram & cpu are never even close to getting to 100% during the build process
its also strange since the error that comes up is not always the same, f.e.
[INFO] - Building for production...
[INFO] node[80787]: pthread_create: Resource temporarily unavailable
[INFO] node:events:505
[INFO] throw er; // Unhandled 'error' event
[INFO] ^
[INFO]
[INFO] Error: spawn /var/lib/jenkins/workspace/MoreFairStaging/frontend/node/node EAGAIN
[INFO] at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
[INFO] at onErrorNT (node:internal/child_process:478:16)
[INFO] at processTicksAndRejections (node:internal/process/task_queues:83:21)
[INFO] Emitted 'error' event on ChildProcess instance at:
[INFO] at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)
[INFO] at onErrorNT (node:internal/child_process:478:16)
[INFO] at processTicksAndRejections (node:internal/process/task_queues:83:21) {
[INFO] errno: -11,
[INFO] code: 'EAGAIN',
[INFO] syscall: 'spawn /var/lib/jenkins/workspace/MoreFairStaging/frontend/node/node',
[INFO] path: '/var/lib/jenkins/workspace/MoreFairStaging/frontend/node/node',
[INFO] spawnargs: [
[INFO] '/var/lib/jenkins/workspace/MoreFairStaging/frontend/node_modules/thread-loader/dist/worker.js',
[INFO] 20
[INFO] ]
[INFO] }
or
[7,371s][warning][os,thread] Failed to start thread - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 0k, detached.
the version for node are 16.16.0 and for npm 8.11; maven is on 3.8.6 with java 17 for maven and java 11 for jenkins (2.346.2)
So the problem with this specific case was that the service config didn't allow for more tasks to spawn
a simple way to fix this (after one week of recherche and trying a various amount of things) is systemctl edit jenkins and add to the config
[Service]
TaskMax=500
the number can vary but the default of 165 you can find out through systemctl show --property=DefaultTasksMax wasn't enough

Has anyone gone through the cloud functions tutorial recently?

I am having the hardest of times just trying to get through the cloud functions tutorial here. Every time I try to do firebase deploy --only functions, I always get an error. My firebase-debug.log looks like this 👉🏾
[debug] [2020-05-05T23:45:15.510Z] ----------------------------------------------------------------------
[debug] [2020-05-05T23:45:15.514Z] Command: /usr/local/bin/node /usr/local/bin/firebase deploy --only functions
[debug] [2020-05-05T23:45:15.515Z] CLI Version: 6.3.0
[debug] [2020-05-05T23:45:15.515Z] Platform: darwin
[debug] [2020-05-05T23:45:15.515Z] Node Version: v8.17.0
[debug] [2020-05-05T23:45:15.515Z] Time: Tue May 05 2020 19:45:15 GMT-0400 (EDT)
[debug] [2020-05-05T23:45:15.515Z] ----------------------------------------------------------------------
[debug]
[debug] [2020-05-05T23:45:15.532Z] > 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"]
[debug] [2020-05-05T23:45:15.533Z] > authorizing via signed-in user
[debug] [2020-05-05T23:45:15.533Z] [iam] checking project cloud-functions-demo-5b1c8 for permissions ["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","firebase.projects.get"]
[debug] [2020-05-05T23:45:15.535Z] > refreshing access token with scopes: ["email","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","openid"]
[debug] [2020-05-05T23:45:15.535Z] >>> HTTP REQUEST POST https://www.googleapis.com/oauth2/v3/token
<request body omitted>
[debug] [2020-05-05T23:45:15.672Z] <<< HTTP RESPONSE 200
[debug] [2020-05-05T23:45:15.684Z] >>> HTTP REQUEST POST https://cloudresourcemanager.googleapis.com/v1/projects/cloud-functions-demo-5b1c8:testIamPermissions
[debug] [2020-05-05T23:45:15.818Z] <<< HTTP RESPONSE 200
[debug] [2020-05-05T23:45:17.852Z] TypeError: Cannot read property 'wanted' of undefined
at /usr/local/lib/node_modules/firebase-tools/lib/checkFirebaseSDKVersion.js:37:51
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
[error]
[error] Error: An unexpected error has occurred.
[debug] [2020-05-05T23:45:48.671Z] ----------------------------------------------------------------------
[debug] [2020-05-05T23:45:48.674Z] Command: /usr/local/bin/node /usr/local/bin/firebase deploy --only functions
[debug] [2020-05-05T23:45:48.675Z] CLI Version: 6.3.0
[debug] [2020-05-05T23:45:48.675Z] Platform: darwin
[debug] [2020-05-05T23:45:48.675Z] Node Version: v8.17.0
[debug] [2020-05-05T23:45:48.675Z] Time: Tue May 05 2020 19:45:48 GMT-0400 (EDT)
[debug] [2020-05-05T23:45:48.676Z] ----------------------------------------------------------------------
[debug]
[debug] [2020-05-05T23:45:48.690Z] > 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"]
[debug] [2020-05-05T23:45:48.690Z] > authorizing via signed-in user
[debug] [2020-05-05T23:45:48.690Z] [iam] checking project cloud-functions-demo-5b1c8 for permissions ["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","firebase.projects.get"]
[debug] [2020-05-05T23:45:48.693Z] >>> HTTP REQUEST POST https://cloudresourcemanager.googleapis.com/v1/projects/cloud-functions-demo-5b1c8:testIamPermissions
[debug] [2020-05-05T23:45:48.887Z] <<< HTTP RESPONSE 200
[debug] [2020-05-05T23:45:50.700Z] TypeError: Cannot read property 'wanted' of undefined
at /usr/local/lib/node_modules/firebase-tools/lib/checkFirebaseSDKVersion.js:37:51
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
[error]
[error] Error: An unexpected error has occurred.
I would appreciate any help in this area! I have already tried deleting the functions directory and just running firebase deploy but that has been unsuccessful. I have also tried downgrading node.js and npm to 6.9.2 (using n) but that hasn't worked either. Any help would be greatly appreciated!
You should bump your cli version from 6.3.0 to 7.1.0 or above, as it fixes the issue reported here https://github.com/firebase/firebase-tools/issues/1469
Maybe also double check that your cloud functions package is up to date? It's hard to tell from your question what your current version is.
So, I went down the rabbit hole online for a few days and finally found a solution through a combination of stackoverflow and GitHub.
First, do the instructions outlined here
Then, lastly do this in your terminal: alias firebase="`npm config get prefix`/bin/firebase" which was from this closed GitHub issue
Hope it helps someone!

Firebase hosting : unable to verify first certificate

Is anybody here to help me with this ?
Whenever I try to initiate firebase hosting, I get this error.
Error is "Server Error. unable to verify the first certificate".
Two months passed but I haven't got the solution. Even I contacted Firebase Support Team, but they didn't help.
Please, help me.
Firebase-debug.log :
You're about to initialize a Firebase project in this directory:
F:\cv_web\build
[info]
=== Project Setup
[info]
[info] First, let's associate this project directory with a Firebase project.
[info] You can create multiple project aliases by running firebase use --add,
[info] but for now we'll just set up a default project.
[info]
[debug] [2019-12-04T21:11:12.162Z] >>> HTTP REQUEST GET https://firebase.googleapis.com/v1beta1/projects?pageSize=100
[debug] [2019-12-04T21:11:13.569Z] <<< HTTP RESPONSE 200
[info] i Using project abhijeetbharti-b42e1 (abhijeetbharti)
[info]
=== Hosting Setup
[info]
[info] Your public directory is the folder (relative to your project directory) that
[info] will contain Hosting assets to be uploaded with firebase deploy. If you
[info] have a build process for your assets, use your build's output directory.
[info]
[info] + Wrote build/404.html
[debug] [2019-12-04T21:11:25.792Z] >>> HTTP REQUEST GET https://www.gstatic.com/firebasejs/releases.json
[debug] [2019-12-04T21:11:27.490Z] Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1321:34)
at TLSSocket.emit (events.js:210:5)
at TLSSocket.EventEmitter.emit (domain.js:478:20)
at TLSSocket._finishInit (_tls_wrap.js:794:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:608:12)
[error]
[error] Error: Server Error. unable to verify the first certificate

Unable to init new firebase project from console

I'm trying to host my webapp on firebase and am currently running into this issue:
My order of operations:
(in root) > npm install -g firebase-tools
> firebase login
> $ npm run build
> cd dist
> firebase init iq18
> (select my desired app in FB dropdown)
> returns: Error: An unexpected error has occurred.
No matter what I try, after running init from my /dist directory, I can not get it to actually deploy to firebase. Full error from the logs:
[info]
=== Project Setup
[info]
[info] First, let's associate this project directory with a Firebase project.
[info] You can create multiple project aliases by running firebase use --add,
[info] but for now we'll just set up a default project.
[info]
[debug] [2018-06-04T19:03:39.456Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects
Mon Jun 04 2018 15:03:39 GMT-0400 (EDT)
[debug] [2018-06-04T19:03:39.812Z] <<< HTTP RESPONSE 200
[info]
=== Iq17 Setup
[debug] [2018-06-04T19:03:42.715Z] TypeError: features[nextFeature] is not a function
at init (/usr/local/lib/node_modules/firebase-tools/lib/init/index.js:13:49)
at /usr/local/lib/node_modules/firebase-tools/lib/init/index.js:14:14
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
[error]
[error] Error: An unexpected error has occurred.
Things I've tried:
Deleted my /dist directory and rebuilt the app
Logged out of firebase and relogged in
Deleted the placeholder app from firebase account
Not quite sure what else I can do to fix this deploy issue.

Cloud Functions of Firebase failed to emulate

When I try to run npm run serve:
"build": "./node_modules/.bin/tsc",
"serve": "npm run build && firebase serve --only functions",
I get an output that says it failed to emulate my functions:
> npm run build && firebase serve --only functions
> functions# build /Users/eliyacohen/apps/app-name/functions
> tsc
=== Serving from '/Users/eliyacohen/apps/app-name'...
i functions: Preparing to emulate functions.
⚠ functions: Failed to emulate payment-create
⚠ functions: Failed to emulate payment-process
When I open firebase-debug.log for further information, I see:
...
Sat Mar 31 2018 18:48:05 GMT+0300 (IDT)
[debug] [2018-03-31T15:48:06.665Z] <<< HTTP RESPONSE 200
[debug] [2018-03-31T15:48:06.666Z] Starting #google-cloud/functions-emulator
[debug] [2018-03-31T15:48:08.254Z] Parsing function triggers
[debug] [2018-03-31T15:48:10.194Z] Error while deploy to emulator: Error: connect ECONNREFUSED 127.0.0.1:5001
at Object.exports._errnoException (util.js:1020:11)
at exports._exceptionWithHostPort (util.js:1043:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
[debug] [2018-03-31T15:48:10.195Z] Error while deploy to emulator: Error: connect ECONNREFUSED 127.0.0.1:5001
at Object.exports._errnoException (util.js:1020:11)
at exports._exceptionWithHostPort (util.js:1043:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
[warn] ⚠ functions: Failed to emulate payment-create
[warn] ⚠ functions: Failed to emulate payment-process
As far as I can understand, it couldn't reach 127.0.0.1:5001 so it could serve these functions locally?
I know that there's nothing wrong with my code, since firebase deploy --only functions deploys my functions with no errors.
I tried to remove entirely Node.js and reinstall it, downgrade and upgrade it. Same goes for the global modules.
My main folder (../functions) is built on Ionic Framework. Does it have something to do with this?
Environment:
Running on MacOS High Sierra
Node.js v6.11.5
NPM version 3.10.10
firebase-tools: 3.17.7 (Global)
firebase-admin: ^5.11.0,
firebase-functions: ^0.9.1
Since I see that lots of people are still encountering with the following error, try to update your node version the latest stable version (or >= 10)
try with different port. example
firebase serve --port 3000 --only functions

Resources