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

18

42

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

[email protected] 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.

Penelopa answered 24/1, 2018 at 18:33 Comment(0)
P
47

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.

Primateship answered 24/1, 2018 at 19:34 Comment(4)
Thank you very much, as i always worked in the same directory i didnt think it will cause the error. Worked like a charm.Penelopa
Well, the lint predeploy hooks are new in projects created by CLI version 3.17.0 and later, which is very new. So you're running stuff that you probably hadn't before. Check your other Firebase projects' firebase.json to see what I mean.Primateship
@DougStevenson This is still an issue, did you manage to follow up internally? P.S. I'm on a MacMonitory
Thanks Doug. You saved me hours of debugging.Ekaterinburg
P
31

"predeploy": [ "npm --prefix \"$RESOURCE_DIR\" run lint" ]

I remove that on firebase.json finally, it started to deploy again

Place answered 28/1, 2019 at 14:7 Comment(1)
It does work, but for what is it used then? Why is it there in the first place?Glarum
I
22

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.

Imbed answered 1/7, 2018 at 8:52 Comment(1)
And what about mac? I think the code is for ESlintRoomful
D
7

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..

Doug answered 25/2, 2020 at 4:30 Comment(0)
K
5

This fixed it for me:

  1. Go to "firebase.json" file in the root directory of the project

  2. Remove everything inside "predeploy" in firebase.json, and it'll stop running the script which is causing issues.

Kaduna answered 6/9, 2022 at 11:13 Comment(0)
M
3

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"
    ]
  }
}
Mccalla answered 18/10, 2018 at 9:45 Comment(0)
U
3

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

Untoward answered 16/3, 2022 at 20:45 Comment(0)
D
3
"redeploy": [
    "npm --prefix \"%RESOURCE_DIR%\" run lint"
]

Use redeploy instead predeploy

Dismissal answered 9/12, 2022 at 5:52 Comment(2)
redeploy worked for me.Thyrotoxicosis
It works because redeploy gets ignored. Actual key is predeploy.Noncooperation
R
2

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

Racketeer answered 5/4, 2019 at 15:57 Comment(0)
L
2
"predeploy": [ "npm --prefix \"$RESOURCE_DIR\" run lint" ]

I remove that on firebase.json finally, it works for me.

Lavallee answered 21/7, 2022 at 22:22 Comment(0)
I
1

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.

Isidraisidro answered 24/6, 2018 at 20:59 Comment(0)
R
1

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

Reproach answered 1/6, 2020 at 15:10 Comment(0)
C
0

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",
    ...
}
Cubiculum answered 12/3, 2018 at 3:25 Comment(0)
D
0

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"
    ]
  }
}
Dabchick answered 23/12, 2018 at 18:31 Comment(0)
N
0

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 :)

Natalia answered 17/3, 2019 at 2:0 Comment(0)
W
0

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

Werby answered 13/12, 2021 at 4:24 Comment(0)
R
0

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

Ronnironnica answered 5/4, 2022 at 19:25 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewPosthorse
P
0

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 😋

Platelayer answered 6/6, 2022 at 21:18 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.