74

I have a fresh install of firebase tools (following this tutorial) and I'm trying to upload my first firebase function. I get this issue with the hello-world example that they initialise when you run firebase init (The only set up the functions CLI feature during the init)

If I replace $RESOURCE_DIR in firebase.json with my functions folder it works, but of course that Is bad practice and I'd like to find a proper $RESOURCE_DIR replacement that works.

PS D:\workspace\firebase-functions> firebase deploy

    === Deploying to 'newagent-5221d'...

i  deploying functions
Running command: npm --prefix $RESOURCE_DIR run lint
npm ERR! path D:\workspace\firebase-functions\$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 'D:\workspace\firebase-functions\$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\dtlut\AppData\Roaming\npm-cache\_logs\2018-01-19T15_57_22_990Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code4294963238
2
  • Could you outline the exact series of steps you take to reproduce this, starting with the moment you run firebase init? Commented Jan 19, 2018 at 17:51
  • I tried it after just init and after uncommenting the hello world code. Both gave this issue. But the accepted answer solves it. Commented Jan 19, 2018 at 20:50

14 Answers 14

137

Try to replace $RESOURCE_DIR with %RESOURCE_DIR% in your firebase.json file.

Multi platform solution

As seen on this post let's summarize the configuration for the different platforms you are running on:

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"
]
6
  • @DaanLuttik Are you using Windows? Commented Jan 19, 2018 at 21:10
  • Yes, I am using Windows Commented Jan 19, 2018 at 21:38
  • 11
    Note that this is a workaround, it's not a solution. This won't be helpful for teams that work across platforms, as they will each have to maintain their own copy of a file that normally belongs in source control. I've raised this issue internally with the Firebase team, and things make change here in the future. Commented Jan 21, 2018 at 18:22
  • 1
    Yeah I noticed. But for me at least its fine. It'd would be nice if there was a cross-platform solution Commented Jan 22, 2018 at 14:40
  • The file to be edited here is of course package,json in the root folder of your local firebase project
    – matthiku
    Commented Feb 1, 2018 at 12:51
57

It wants to lint your cloud functions, meaning it will check your code for obvious errors like a compiled language would throw errors at compile time.

It's not necessary, you can always remove it by going into firebase.json and updating functions.predeploy to be an empty array.

  "functions": {
    "predeploy": [],
    "source": "functions" 
  }

What is "Linting"?

3
  • i have tried all of the above replacements,but sometimes it showed an error while deploying single functions without replacing existing function,so inside firebase.json file i replaced all codes with this>>> {} it worked for me,
    – Rajesh
    Commented Aug 12, 2018 at 6:15
  • Linting is there for a reason. It may reduce the risk of buggy code resulting in high bills (infinite loops, promises that aren't resolved,...). The solution from Inzamam Malik seems more appropriate to me.
    – Koen
    Commented Feb 7, 2019 at 13:52
  • Thanks! removing predeploy command worked. Commented Mar 30, 2021 at 17:20
35

you can simply make your firebase.json file like this:

{
  "functions": {
    "predeploy": [
      "npm --prefix ./functions/ run lint",
      "npm --prefix ./functions/ run build"
    ]
  }
}

what I'm doing is replace $RESOURCE_DIR with hard coded path of function folder itis working nice for me

2
  • 1
    Worth pointing out my firebase.json only contained the first line (... lint",, but replacing \"$RESOURCE_DIR\" with ./functions/ in that line resolved the issue anyway.
    – Jake Lee
    Commented Nov 1, 2018 at 10:03
  • 1
    this is very useful
    – neo33
    Commented Feb 12, 2019 at 5:25
14

SUMMARIZING

  1. Install ESLint locally to add "devDependencies" to package.json. Run:

     `npm install eslint --save-dev`
    
  2. Workaround for Windows as stated above. Change firebase.json:

     `npm --prefix $RESOURCE_DIR run lint` to `npm --prefix %RESOURCE_DIR% run lint`
    
  3. Optionally, add the following to package.json:

     "scripts": { "lint": "eslint"} or "scripts": { "lint": "eslint.js"}
    
6

locate the firebase.json file and then change these lines

"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"

to

"npm --prefix \"%RESOURCE_DIR%\" run lint",
"npm --prefix \"%RESOURCE_DIR%\" run build"

it'll work

2
  • 1
    This worked for me too but I don't understand why it works. Please explain.
    – CodeSlave
    Commented Nov 5, 2018 at 18:32
  • actually in windows it doesnt understands the '$' symbol it is only meant for linux systems but windows understands the ' %' symbol Commented Nov 6, 2018 at 7:25
2

Modify in firebase.json from "npm --prefix $RESOURCE_DIR run lint" to "npm --prefix %RESOURCE_DIR% run lint"

2

side note, if you're using yarn (and not npm), you need to specify --cwd param (instead of --prefix)

firebase.json example:

{
  ...
  "functions": {
    "predeploy": [
      "yarn --cwd \"$RESOURCE_DIR\" lint",
      "yarn --cwd \"$RESOURCE_DIR\" build"
    ]
  },
  ...
}

1

My problem was my node version. I got this error after installing packages with the wrong node version. I ran yarn setup with node 16 but my project uses node 14. I switched to node 14 before trying to deploy and received this error. I tried the fixes mentioned here and finally realized what my problem was. This is one of those errors which is disinformative...

1

My approach to fixing this issue was to remove the period (.) after the eslint in package.json.

So, change:

 "scripts": {
    "lint": "eslint.",
 }

To:

"scripts": {
    "lint": "eslint",
}

0

This one should solve the issue without workaround

npm install -g git://github.com/firebase/firebase-tools#master

please try this installation again in ur project folder it should solve the issue.

1
  • 1
    I can confirm latest version hasn't fixed the issue, just installed on a fresh machine (W10, Powershell) and encountered it.
    – Jake Lee
    Commented Nov 1, 2018 at 10:04
0

It is working my cloud function deploy successfully

"functions": {
"predeploy": [
  "npm --prefix \"%RESOURCE_DIR%\" run lint",
  "npm --prefix \"%RESOURCE_DIR%\" run build"
],`enter code here`
"source": "functions"
0

None of the previous suggestions worked for me. So I deleted the function part of the firebase.json file as in below by only keeping the hosting part. Then, I deployed the app successfully without functions.

Then, I cd into functions from the terminal and deployed the functions by using firebase deploy --only functions

{

  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}
0

Another possible issue is there are some errors in the code for example, I got this error message

  55:47  error  Expected '!==' and instead saw '!='  eqeqeq
  69:47  error  Expected '!==' and instead saw '!='  eqeqeq

After I fixed and deploy again and it work. this attached image

0

for anyone out there, you might as well run npm install first just to make sure everything is in place before deploying. Worked for me

Not the answer you're looking for? Browse other questions tagged or ask your own question.