firebase deploy fails with lots of errors [duplicate] - node.js

I was having issues with firebase deploy command recently. After firebase deploy command all others were being deployed except firebase (storage, database etc) So I decided to reinstall firebase to fix this situation but after reinstall my problem got bigger. Now none of them are deployed with the following error:
i deploying database, functions
Running command: npm --prefix $RESOURCE_DIR run lint
npm ERR! path C:\Users\faruk\Google Drive\Android\firebase\1\$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\faruk\Google Drive\Android\firebase\1\$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\faruk\AppData\Roaming\npm-cache\_logs\2018-01-24T18_21_34_878Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code4294963238
After a bit research, I saw some topics about this which advice to change
$RESOURCE_DIR to %RESOURCE_DIR%
in windows systems (I am using windows 10 btw). So, I edited my firebase.json file which is in one upper level of my functions folder. like this. (I don't know if this is the right file that I should edit)
"database": {
"rules": "database.rules.json"
},
"functions": {
"predeploy": [
"npm --prefix %RESOURCE_DIR% run lint"
]
}
}
but after this edit, I started to get another error message like this.
i deploying database, functions
Running command: npm --prefix %RESOURCE_DIR% run lint
Usage: npm <command>
where <command> is one of:
access, adduser, bin, bugs, c, cache, completion, config,
ddp, dedupe, deprecate, dist-tag, docs, doctor, edit,
explore, get, help, help-search, i, init, install,
install-test, it, link, list, ln, login, logout, ls,
outdated, owner, pack, ping, prefix, profile, prune,
publish, rb, rebuild, repo, restart, root, run, run-script,
s, se, search, set, shrinkwrap, star, stars, start, stop, t,
team, test, token, tst, un, uninstall, unpublish, unstar,
up, update, v, version, view, whoami
npm <command> -h quick help on <command>
npm -l display full usage info
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
C:\Users\faruk\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm#5.6.0 C:\Program Files\nodejs\node_modules\npm
Error: functions predeploy error: Command terminated with non-zero exit code1
Any advice is appreciated. Thanks in advance.

The error stems from the fact that you have a space somewhere in the path of your project ("Google Drive"):
C:\Users\faruk\Google Drive\Android\firebase\1\$RESOURCE_DIR\package.json
Unfortunately, this is confusing the npm command line, and it's taking that as two arguments separated by that space.
Normally, I would expect to be able to place quotes around the whole thing to keep the space from being interpreted that way. So I tried this:
"predeploy": [
"npm --prefix \"%RESOURCE_DIR%\" run lint"
]
And it works for me.
I'll follow up with the Firebase team internally about this issue, as well as the fact that changes need to be made for Windows.

What happens actually is that in Windows, firebase.json contains the following by default:
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
Modify it to:
"predeploy": [
"npm --prefix \"%RESOURCE_DIR%\" run lint"
]
It worked for me, hope it works for you.

"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
I remove that on firebase.json finally, it started to deploy again

For me, none of the above worked. Initially, on a fresh firebase-function install, I was getting error on non-zero exit code2. so I removed the functions directory, re-installed, but on the functions directory configuration step, I chose to say "no" to the add-lint step.
once I chose to not include lint, I got error non-zero exit code1.
from there checked my firebase.json file and looked at the predeploy script. because the deployment process was failing at this point, it was where I started. my firebase.json file looked like this:
{
"functions": {
"predeploy": [ "npm --prefix \"$RESOURCE_DIR\" run lint" ]
}
}
for some reason I intuitively thought to remove the lint in the predeploy script. this fixed everything. Im on MacOS by the way..

This what work for me after change $RESOURCE_DIR to %RESOURCE_DIR% in firebase.json
{
"functions": {
"predeploy": [
"npm --prefix \"%RESOURCE_DIR%\" run lint",
"npm --prefix \"%RESOURCE_DIR%\" run build"
]
}
}

type this into your console ' firebase deploy --only hosting'. It worked for me

Try running npm install inside the functions folder of the project.
Maybe you are importing one or more node modules in index.ts that isn't installed, in this case you need to install it by running like:
npm install <somemodule> --save

I had the same problem in Windows. What I did was I copied all the files which were in functions folder and passed it to %RESOURCE_DIR% folder and then I run the Firebase deploy and it deployed successfully.

I fixed it: you must pay attention at another place
Do you see the error description
$ firebase deploy --only functions
=== Deploying to 'fix-firebase-functions'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions# lint C:\Users\vuduc\OneDrive\Tài liệu\Code tutotial practice\test\functions
> eslint .
C:\Users\vuduc\OneDrive\Tài liệu\Code tutotial practice\test\functions\index.js
37:16 warning Avoid nesting promises promise/no-nesting
42:13 error Expected catch() or return promise/catch-or-return
42:13 warning Avoid nesting promises promise/no-nesting
42:31 error Each then() should return a value or throw promise/always-return
✖ 4 problems (2 errors, 2 warnings)
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\vuduc\AppData\Roaming\npm-cache\_logs\2020-06-01T14_38_16_060Z-debug.log
events.js:287
throw er; // Unhandled 'error' event
^
Error: spawn npm --prefix "%RESOURCE_DIR%" run lint ENOENT
at notFoundError (C:\Users\vuduc\AppData\Local\Yarn\Data\global\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)
at verifyENOENT (C:\Users\vuduc\AppData\Local\Yarn\Data\global\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:40:16)
at ChildProcess.cp.emit (C:\Users\vuduc\AppData\Local\Yarn\Data\global\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:27:25)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess.cp.emit (C:\Users\vuduc\AppData\Local\Yarn\Data\global\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:30:37)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn npm --prefix "%RESOURCE_DIR%" run lint',
path: 'npm --prefix "%RESOURCE_DIR%" run lint',
spawnargs: []
Error: functions predeploy error: Command terminated with non-zero exit code1
error deploy cloud functions
You need to scroll up to see the error description, the line
functions predeploy error: Command terminated with non-zero exit code1
is just a general description that there is an error to fix before deploying.
This is what really needs attention, which instructions do you need to fix?
✖ 4 problems (2 errors, 2 warnings)
Pay attention here

This fixed it for me:
Go to "firebase.json" file in the root directory of the project
Remove everything inside "predeploy" in firebase.json, and it'll stop running the script which is causing issues.

"redeploy": [
"npm --prefix \"%RESOURCE_DIR%\" run lint"
]
Use redeploy instead predeploy

For me, the issue was (I presume) because firebase couldn't find the script.
Didn't work:
{
"hosting": {
"predeploy": "predeploy.sh",
...
}
Running command: predeploy.sh
events.js:160
throw er; // Unhandled 'error' event
^
Error: spawn predeploy.sh ENOENT
at exports._errnoException (util.js:1020:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:367:16)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3
Error: hosting predeploy error: Command terminated with non-zero exit code1
Did work: (note the ./)
{
"hosting": {
"predeploy": "./predeploy.sh",
...
}

When Using VS code ,open folder of Firecast (this helps open firebase.json of Resource Directory ) In firebase.json change the code of file to this:
{
"functions": {
"predeploy": [
"npm --prefix \"%RESOURCE_DIR%\" run lint",
"npm --prefix \"%RESOURCE_DIR%\" run build"
]
}
}

In my case I created a function to print logs, something like this:
function log(tag: string, value: any) {
console.log(tag, JSON.stringify(value));
}
When I add async in front of it, it starts exploding the build :)

I solve this by re-initiating firebase init, then not selecting to use eslint. Deploy worked after that.

This can also happen if you dont choose a blaze plan from firebase. basically deployment of cloud functions require a blaze plan activated

I'm on mac and since I moved my firebase project to another directory/laptop, I had this exact issue.
I resolved my issue by just re-initializing my firebase project.
firebase init
Be careful though. Since most of your files already exist, it might want to override them. Just say no to all override questions. Unless of course all your code is pushed to the firebase console ... which it should be 😋

"predeploy": [ "npm --prefix \"$RESOURCE_DIR\" run lint" ]
I remove that on firebase.json finally, it works for me.

Related

how to resolve Error: functions predeploy error: Command terminated with non-zero exit code 1

trying to deploy firebase functions , and I am now lost , no matter what i try nothing is working for me
I have tried this and this also this and this along with multiple other solutions i found on stackoverflow and other sites (tried everything that i can find related to this error) , and nothing seems to be working for me
I am using Node v14.16.0 and firebase tools version 9.8.0
does this mean i am missing some packages in firebase-tools? i have also installed the firebase-tools multiple times just to make sure each and everything is installed correctly, tried pretty much every thing in above mentioned links but nothing seems to be working
this is what i am stuck at:
13:37 error Parsing error: Unexpected token =>
✖ 1 problem (1 error, 0 warnings)
events.js:292
throw er; // Unhandled 'error' event
^
Error: spawn npm --prefix "C:\Users\r\Desktop\cfnc\functions" run lint ENOENT
at notFoundError (C:\Users\r\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)
at verifyENOENT (C:\Users\r\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:40:16)
at ChildProcess.cp.emit (C:\Users\r\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:27:25)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess.cp.emit (C:\Users\r\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:30:37)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn npm --prefix "C:\\Users\\r\\Desktop\\cfnc\\functions" run lint',
path: 'npm --prefix "C:\\Users\\r\\Desktop\\cfnc\\functions" run lint',
spawnargs: []
}
Error: functions predeploy error: Command terminated with non-zero exit code1
Having trouble? Try firebase [command] --help
can someone please help point me to the correct solution for this issue ?
Thanks
I did some research in your error and the part in your error that says:
path: 'npm --prefix "C:\\Users\\r\\Desktop\\cfnc\\functions" run lint',
spawnargs: []
Means that you don't have the lint script in the package.json. If you modified properly your package json as in this:
Linux
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
PowerShell
"predeploy": [
"npm --prefix $Env:RESOURCE_DIR run lint"
]
Cmd.exe
"predeploy": [
"npm --prefix %RESOURCE_DIR% run lint"
]
And it didn't work I suggest that you try the steps on this thread of github. Also it would be helpful that you share your package.json

firebase deploy No files matching the pattern "'src/**/*'" were found

iam trying to deploy my first cloud function on firebase but the problem is that it always says that there is something wrong and no files are matching the pattern i dont know why even that the index.ts is where it is supposed to be
the error code is
=== Deploying to 'mscmu-aeab1'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions# lint C:\Users\fahmi\msc_mu\cloud_functions\functions
> eslint 'src/**/*'
Oops! Something went wrong! :(
ESLint: 7.9.0
No files matching the pattern "'src/**/*'" were found.
Please check for typing mistakes in the pattern.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions# lint: `eslint 'src/**/*'`
npm ERR! Exit status 2
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\fahmi\AppData\Roaming\npm-cache\_logs\2020-09-26T22_01_33_578Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code2
https://i.imgur.com/rb10Tsi.png
In your functions package.json edit the lint script as follows:
eslint --ext .ts src
This problem is solved in this commit.
In your functions folders open package.json and edit the line starting with lint like this:
"lint": "eslint \"src/**/*\""
This issue is resolved with the Firebase CLI version 8.12.0. The update is to escape quotes around the argument to eslint as shown in this commit.

Node app on Plesk - Environment variables on custom scripts

I'm running a Node v12 app on Plesk Obsidian v18.0.29
I've set the required environment variables in the dedicated section:
Also the "Application Mode" should in theory act as NODE_ENV for the process and seems to do so.
Just FYI I also tried adding it to the "Custom environment variables" but that doesn't solve my problem.
The problem being that, despite the app itself running fine, when I try to run a custom script (DB migrations) Plesk seems to ignore these variables, as you can see from Using environment "development".
> REDACTED#0.1.0 migrate /var/www/vhosts/REDACTED/httpdocs
> sequelize db:migrate
[4mSequelize CLI [Node: 12.4.0, CLI: 5.4.0, ORM: 5.8.7][24m
Loaded configuration file "config/database.js".
Using environment "development".
[31mERROR:[39m Error parsing url: undefined
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! REDACTED#0.1.0 migrate: `sequelize db:migrate`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the REDACTED#0.1.0 migrate 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! /var/www/vhosts/REDACTED/.npm/_logs/2020-09-04T08_13_39_221Z-debug.log
If I try to create a custom script that forces the NODE_ENV variable, the correct environment is considered, but the other variables are still ignored.
For example, by creating a script called migrateprod and running it through Plesk:
"scripts": {
"test": "npm run test:unit && npm run test:e2e",
"test:unit": "mocha tests/unit/**/**.spec.js --require ./tests/setup.js --exit",
"test:e2e": "mocha tests/e2e/**/**.spec.js --require ./tests/setup.js --exit",
"start": "node index.js",
"watch": "nodemon index.js",
"migrate": "sequelize db:migrate",
"migrateprod": "NODE_ENV=production sequelize db:migrate",
"migrate:down": "sequelize db:migrate:undo:all",
"cli": "node cli/index.js"
},
I can now see the environment production but the DATABASE_URL variable is not found, getting an error instead:
> REDACTED#0.1.0 migrateprod /var/www/vhosts/REDACTED/httpdocs
> NODE_ENV=production sequelize db:migrate
[4mSequelize CLI [Node: 12.4.0, CLI: 5.4.0, ORM: 5.8.7][24m
Loaded configuration file "config/database.js".
Using environment "production".
[31mERROR:[39m Error parsing url: undefined
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! REDACTED#0.1.0 migrateprod: `NODE_ENV=production sequelize db:migrate`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the REDACTED#0.1.0 migrateprod 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! /var/www/vhosts/REDACTED/.npm/_logs/2020-09-04T08_21_51_188Z-debug.log
Bottom line is, Plesk seems to ignore or avoid setting the environment variables while running custom scripts. I tried searching around but I couldn't find any similar case, which makes me think I'm just missing something.
Any ideas? Thanks in advance for your time!
Turns out Plesk does not forward environment variables to custom scripts, no matter how hard you try. So I modified the package.json to set the variables on the fly before running the script.
"scripts": {
... other scripts ...
"cli": "export $(cat ../.env.production | xargs) && node cli/index.js"
},
There's an .env file in a protected folder outside the application file system, from which I get the variables and send them as args to the custom script.
Not the most elegant solution, but it sorts out the problem.

Firebase Function Deployment issue: package.json not found in %RESOURCE_DIR%

I having problem of deploying Firebase Cloud Functions.
Steps to reproduce
firebase init
select function only
select Firebase Project
select Javascript
use ESLint
install dependencies with npm now
Run firebase deploy
Expected Result
Expecting firebase-tools to deploy the cloud functions.
Actual Result
Receive the following error message:
λ firebase deploy
=== Deploying to '<projects>'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
npm ERR! path ...path\firebaseFunction\%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 '...path\firebaseFunction\%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! ...path\AppData\Roaming\npm-cache\_logs\2018-06-17T10_02_45_577Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code4294963238
I have tried googled it and follow the solutions on below link but it doesn't work to me:
https://github.com/firebase/firebase-tools/issues/610
Please help!
Thank you.
Try replacing the string "$RESOURCE_DIR" with "%RESOURCE_DIR%" in your "firebase.json" file.
Now run the deploy command again. It worked for me.
Explanation: This fix is for Windows because %RESOURCE_DIR% will be recognized as an environment variable only by Windows command-line interpreters. As an ultimate consequence, the project isn't cross-platform anymore, as mentioned in the answer of this similar question.
1. In firebase.json file
try and replace $RESOURCE_DIRwith %RESOURCE_DIR%
and
"npm --prefix $RESOURCE_DIR run lint" to "npm --prefix %RESOURCE_DIR% run lint"
(the above one just worked around )
2. npm install -g git://github.com/firebase/firebase-tools#master
please try this installation again in ur project folder it should solve the issue
I had the same problem just remove the predeploy from firebase.json file and it will work fine
It looks like you're either using an old version of the Firebase CLI, or a project that was initialized with an old version. The cleanest thing to do would be to upgrade your CLI:
npm install -g firebase-tools
And create a whole new project from scratch with firebase init. Then, reconstruct your new project with the code from the old project.
Solution
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
to
"functions": {
"predeploy": [
"npm --prefix \"%RESOURCE_DIR%\" run lint",
"npm --prefix \"%RESOURCE_DIR%\" run build"
]
}
Step1: open firebase.json you will show this JSON file
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
Step2: Delete "npm --prefix \"$RESOURCE_DIR\" run lint", and "npm --prefix \"$RESOURCE_DIR\" run build"
"functions": {
"predeploy": []
}
Now deploy, it works fine

Firebase deploy errors starting with non-zero exit code (space in project path)

I was having issues with firebase deploy command recently. After firebase deploy command all others were being deployed except firebase (storage, database etc) So I decided to reinstall firebase to fix this situation but after reinstall my problem got bigger. Now none of them are deployed with the following error:
i deploying database, functions
Running command: npm --prefix $RESOURCE_DIR run lint
npm ERR! path C:\Users\faruk\Google Drive\Android\firebase\1\$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\faruk\Google Drive\Android\firebase\1\$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\faruk\AppData\Roaming\npm-cache\_logs\2018-01-24T18_21_34_878Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code4294963238
After a bit research, I saw some topics about this which advice to change
$RESOURCE_DIR to %RESOURCE_DIR%
in windows systems (I am using windows 10 btw). So, I edited my firebase.json file which is in one upper level of my functions folder. like this. (I don't know if this is the right file that I should edit)
"database": {
"rules": "database.rules.json"
},
"functions": {
"predeploy": [
"npm --prefix %RESOURCE_DIR% run lint"
]
}
}
but after this edit, I started to get another error message like this.
i deploying database, functions
Running command: npm --prefix %RESOURCE_DIR% run lint
Usage: npm <command>
where <command> is one of:
access, adduser, bin, bugs, c, cache, completion, config,
ddp, dedupe, deprecate, dist-tag, docs, doctor, edit,
explore, get, help, help-search, i, init, install,
install-test, it, link, list, ln, login, logout, ls,
outdated, owner, pack, ping, prefix, profile, prune,
publish, rb, rebuild, repo, restart, root, run, run-script,
s, se, search, set, shrinkwrap, star, stars, start, stop, t,
team, test, token, tst, un, uninstall, unpublish, unstar,
up, update, v, version, view, whoami
npm <command> -h quick help on <command>
npm -l display full usage info
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
C:\Users\faruk\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm#5.6.0 C:\Program Files\nodejs\node_modules\npm
Error: functions predeploy error: Command terminated with non-zero exit code1
Any advice is appreciated. Thanks in advance.
The error stems from the fact that you have a space somewhere in the path of your project ("Google Drive"):
C:\Users\faruk\Google Drive\Android\firebase\1\$RESOURCE_DIR\package.json
Unfortunately, this is confusing the npm command line, and it's taking that as two arguments separated by that space.
Normally, I would expect to be able to place quotes around the whole thing to keep the space from being interpreted that way. So I tried this:
"predeploy": [
"npm --prefix \"%RESOURCE_DIR%\" run lint"
]
And it works for me.
I'll follow up with the Firebase team internally about this issue, as well as the fact that changes need to be made for Windows.
What happens actually is that in Windows, firebase.json contains the following by default:
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
Modify it to:
"predeploy": [
"npm --prefix \"%RESOURCE_DIR%\" run lint"
]
It worked for me, hope it works for you.
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
I remove that on firebase.json finally, it started to deploy again
For me, none of the above worked. Initially, on a fresh firebase-function install, I was getting error on non-zero exit code2. so I removed the functions directory, re-installed, but on the functions directory configuration step, I chose to say "no" to the add-lint step.
once I chose to not include lint, I got error non-zero exit code1.
from there checked my firebase.json file and looked at the predeploy script. because the deployment process was failing at this point, it was where I started. my firebase.json file looked like this:
{
"functions": {
"predeploy": [ "npm --prefix \"$RESOURCE_DIR\" run lint" ]
}
}
for some reason I intuitively thought to remove the lint in the predeploy script. this fixed everything. Im on MacOS by the way..
This what work for me after change $RESOURCE_DIR to %RESOURCE_DIR% in firebase.json
{
"functions": {
"predeploy": [
"npm --prefix \"%RESOURCE_DIR%\" run lint",
"npm --prefix \"%RESOURCE_DIR%\" run build"
]
}
}
type this into your console ' firebase deploy --only hosting'. It worked for me
Try running npm install inside the functions folder of the project.
Maybe you are importing one or more node modules in index.ts that isn't installed, in this case you need to install it by running like:
npm install <somemodule> --save
I had the same problem in Windows. What I did was I copied all the files which were in functions folder and passed it to %RESOURCE_DIR% folder and then I run the Firebase deploy and it deployed successfully.
I fixed it: you must pay attention at another place
Do you see the error description
$ firebase deploy --only functions
=== Deploying to 'fix-firebase-functions'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions# lint C:\Users\vuduc\OneDrive\Tài liệu\Code tutotial practice\test\functions
> eslint .
C:\Users\vuduc\OneDrive\Tài liệu\Code tutotial practice\test\functions\index.js
37:16 warning Avoid nesting promises promise/no-nesting
42:13 error Expected catch() or return promise/catch-or-return
42:13 warning Avoid nesting promises promise/no-nesting
42:31 error Each then() should return a value or throw promise/always-return
✖ 4 problems (2 errors, 2 warnings)
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\vuduc\AppData\Roaming\npm-cache\_logs\2020-06-01T14_38_16_060Z-debug.log
events.js:287
throw er; // Unhandled 'error' event
^
Error: spawn npm --prefix "%RESOURCE_DIR%" run lint ENOENT
at notFoundError (C:\Users\vuduc\AppData\Local\Yarn\Data\global\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)
at verifyENOENT (C:\Users\vuduc\AppData\Local\Yarn\Data\global\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:40:16)
at ChildProcess.cp.emit (C:\Users\vuduc\AppData\Local\Yarn\Data\global\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:27:25)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess.cp.emit (C:\Users\vuduc\AppData\Local\Yarn\Data\global\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:30:37)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn npm --prefix "%RESOURCE_DIR%" run lint',
path: 'npm --prefix "%RESOURCE_DIR%" run lint',
spawnargs: []
Error: functions predeploy error: Command terminated with non-zero exit code1
error deploy cloud functions
You need to scroll up to see the error description, the line
functions predeploy error: Command terminated with non-zero exit code1
is just a general description that there is an error to fix before deploying.
This is what really needs attention, which instructions do you need to fix?
✖ 4 problems (2 errors, 2 warnings)
Pay attention here
This fixed it for me:
Go to "firebase.json" file in the root directory of the project
Remove everything inside "predeploy" in firebase.json, and it'll stop running the script which is causing issues.
"redeploy": [
"npm --prefix \"%RESOURCE_DIR%\" run lint"
]
Use redeploy instead predeploy
For me, the issue was (I presume) because firebase couldn't find the script.
Didn't work:
{
"hosting": {
"predeploy": "predeploy.sh",
...
}
Running command: predeploy.sh
events.js:160
throw er; // Unhandled 'error' event
^
Error: spawn predeploy.sh ENOENT
at exports._errnoException (util.js:1020:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:367:16)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3
Error: hosting predeploy error: Command terminated with non-zero exit code1
Did work: (note the ./)
{
"hosting": {
"predeploy": "./predeploy.sh",
...
}
When Using VS code ,open folder of Firecast (this helps open firebase.json of Resource Directory ) In firebase.json change the code of file to this:
{
"functions": {
"predeploy": [
"npm --prefix \"%RESOURCE_DIR%\" run lint",
"npm --prefix \"%RESOURCE_DIR%\" run build"
]
}
}
In my case I created a function to print logs, something like this:
function log(tag: string, value: any) {
console.log(tag, JSON.stringify(value));
}
When I add async in front of it, it starts exploding the build :)
I solve this by re-initiating firebase init, then not selecting to use eslint. Deploy worked after that.
This can also happen if you dont choose a blaze plan from firebase. basically deployment of cloud functions require a blaze plan activated
I'm on mac and since I moved my firebase project to another directory/laptop, I had this exact issue.
I resolved my issue by just re-initializing my firebase project.
firebase init
Be careful though. Since most of your files already exist, it might want to override them. Just say no to all override questions. Unless of course all your code is pushed to the firebase console ... which it should be 😋
"predeploy": [ "npm --prefix \"$RESOURCE_DIR\" run lint" ]
I remove that on firebase.json finally, it works for me.

Resources