Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy error on Windows: "Running command: npm --prefix "$RESOURCE_DIR" run lint" #822

Closed
001AJD opened this issue Jul 9, 2018 · 24 comments

Comments

@001AJD
Copy link

001AJD commented Jul 9, 2018

=== Deploying to 'help-baba'...

i deploying functions, hosting
Running command: npm --prefix "$RESOURCE_DIR" run lint
npm ERR! Windows_NT 10.0.17134
npm ERR! argv "D:\installationFolder\nodejs\node.exe" "D:\installationFolder\nodejs\node_modules\npm\bin\npm-cli.js" "--prefix" "%RESOURCE_DIR%" "run" "lint"
npm ERR! node v6.11.5
npm ERR! npm v3.10.10
npm ERR! path G:\HelpBaba%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 'G:\HelpBaba%RESOURCE_DIR%\package.json'
npm ERR! enoent ENOENT: no such file or directory, open 'G:\HelpBaba%RESOURCE_DIR%\package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR! G:\HelpBaba\npm-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code4294963238

I am trying to deploy on firebase but its giving this error. Please Help!

@laurenzlong
Copy link
Contributor

What's your firebase-tools version?

Run "firebase --version"

@laurenzlong
Copy link
Contributor

And what does your "firebase.json" look like?

@laurenzlong laurenzlong changed the title Cant deploy project on firebase Issue with pre-deploy script Jul 18, 2018
@laurenzlong
Copy link
Contributor

And what is your platform? (Windows vs OS X)

@001AJD
Copy link
Author

001AJD commented Jul 19, 2018

I am on windows 10
firebase version 3.19.3

This is how my firebase.json looks like

{
"hosting": {
"public": "public",
"rewrites": [
{
"source": "",
"function": "app"
}
],
"ignore": [
"firebase.json",
"
/.*",
"/node_modules/"
]
},
"functions": {
"predeploy": [
"npm --prefix "$RESOURCE_DIR" run lint"
],
"source": "functions"
},
"database": {
"rules": "database.rules.json"
}
}
@laurenzlong

@001AJD
Copy link
Author

001AJD commented Jul 19, 2018

@laurenzlong I was able to deploy my static pages successfully but when i am trying to deploy firebase functions I am getting errors.. and now I am getting the following errors:

G:\HelpBaba>firebase deploy

=== Deploying to 'help-baba'...

i deploying database, functions, hosting
Running command: npm --prefix "$RESOURCE_DIR" run lint

functions@ lint G:\HelpBaba%RESOURCE_DIR%
eslint .

Oops! Something went wrong! :(

ESLint: 5.1.0.
No files matching the pattern "." were found.
Please check for typing mistakes in the pattern.

npm ERR! Windows_NT 10.0.17134
npm ERR! argv "D:\installationFolder\nodejs\node.exe" "D:\installationFolder\nodejs\node_modules\npm\bin\npm-cli.js" "--prefix" "%RESOURCE_DIR%" "run" "lint"
npm ERR! node v6.11.5
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! functions@ lint: eslint .
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the functions@ lint script 'eslint .'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the functions package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! eslint .
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs functions
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls functions
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! Please include the following file with any support request:
npm ERR! G:\HelpBaba\npm-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code1

Having trouble? Try firebase deploy --help

when i do "firebase serve --only hosting,functions" everything works fine locally. Error occurs when deploying.

@laurenzlong
Copy link
Contributor

laurenzlong commented Jul 19, 2018

Thanks for posting, looks like the pre-deploy linting script that was set up by "firebase init" is not behaving well. I'll have to debug further as to why that's happening on windows (I thought we had fixed it). In the meanwhile, you can just delete the following from firebase.json:

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

@laurenzlong laurenzlong changed the title Issue with pre-deploy script Deploy error on Windows: "Running command: npm --prefix "$RESOURCE_DIR" run lint" Jul 20, 2018
@laurenzlong
Copy link
Contributor

laurenzlong commented Jul 21, 2018

I think I figured out what's going on. Windows PowerShell has a different syntax for environment variables than Windows Cmd.exe/Command Prompt. It uses the syntax $Env:FOO instead of %FOO%(see article) During deployment, Firebase CLI was dynamically substituting \"$RESOURCE_DIR\" for %RESOURCE_DIR% when it detects that the system is Windows, that is not working for PowerShell (and may not working for some other command line tools on Windows as well)

In the April update to Windows 10, Microsoft made PowerShell the default command line app, which is probably why there's so many users that have run into this issue lately.

If you are a Windows user, and you are running into this bug, you have a couple of options.

  1. Completely remove the "predeploy" field from firebase.json if you don't actually need linting or building prior to deployment
  2. Edit the predeploy script to use the right syntax for your command line tool:
// firebase.json

// before: (it may not look exactly the same depending on which CLI you were 
// using when you ran "firebase init"
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]

// after: (for PowerShell)
"predeploy": [
"npm --prefix $Env:RESOURCE_DIR run lint"
]

// after: (for Cmd.exe)
"predeploy": [
"npm --prefix %RESOURCE_DIR% run lint"
]

This should hopefully unblock affected users while we try to fix this. If anyone has suggestions on how to make a script work across platforms and across command line tools, please share!

@001AJD
Copy link
Author

001AJD commented Jul 23, 2018 via email

@001AJD 001AJD closed this as completed Jul 23, 2018
@laurenzlong
Copy link
Contributor

You're welcome! I'm going to reopen the issue so people can see the workaround.

I'm also modifying the behavior of "firebase init" so it doesn't create the predeploy script by default (#836), to lower the number of people that will run into this.

@laurenzlong laurenzlong reopened this Jul 23, 2018
@hgghyxo
Copy link

hgghyxo commented Aug 22, 2018

Not sure if I understood your previous comment fully, but as #836 already merged I assumed you this is fixed, however Functions still has this enabled by default:
I'm on win10 1803, powerShell

firebase --version
4.2.0
"functions": {
  "predeploy": [
    "npm --prefix \"$RESOURCE_DIR\" run lint",
    "npm --prefix \"$RESOURCE_DIR\" run build"
  ]
},

@laurenzlong
Copy link
Contributor

@hgghyxo Was the project initialized before or after you upgraded firebase-tools?

@hgghyxo
Copy link

hgghyxo commented Aug 22, 2018

after :) but to make sure, just run an new test, empty dir, new firebase init same result

@laurenzlong
Copy link
Contributor

Oh I see, you are using TypeScript. For TypeScript, we still default to true for linting, because a pre-deploy hook is already required for building the source code prior to deployment. If this is causing you issues, you can replace \"$RESOURCE_DIR\" with the name of your functions directory (but then you would have to always run firebase deploy from the main project directory), or you can use a format for environment variables that's compatible with PowerShell (I think that would be $Env:RESOURCE_DIR but haven't tested it to know.)

@NicksonYap
Copy link

Thanks for the workaround,

But It's such a bad experience getting started
Shouldn't this be long fixed by now?...

@NicksonYap
Copy link

NicksonYap commented Aug 26, 2018

@laurenzlong

Just to note that I'm using Powershell, Firebase-Tools 4.2.0, Node Js 8.11.4

I tried the one below and it doesn't work. :(

"functions": {
  "predeploy": [
    "npm --prefix $Env:RESOURCE_DIR run lint",
    "npm --prefix $Env:RESOURCE_DIR run build"
  ]
},

This works: :)

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

@ahmadalibaloch
Copy link

@elebitzero
Copy link

I am seeing this issue on Window 8.1 pro with latest 6.0.0 firebase-tools.
This bug has been opened for months. If you don't know how to fix the bug, you should at least update the section "Initialize Firebase SDK for Cloud Functions" (Ref: https://firebase.google.com/docs/functions/get-started) to warn users they have to update the redeploy scripts on windows.

Also, when I googled this issue, I first found an earlier bug (#610) opened Jan 18th which was closed as a duplicate of this bug opened July 9th. That initially cause some additional confusion because I thought the issue was fixed. The original bug should have been left open.

@balatimuz
Copy link

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

This works for me..
Thank you.

@tinaliang
Copy link
Contributor

Closing since we don't have a permanent fix on the immediate horizon. Please see discussions and links for workarounds.

If none of the workarounds work, please open a new issue with your exact problem.

@byronglendon
Copy link

Run npm install from within your functions directory to make sure you have the correct node modules installed for your functions.

@thanhtutzaw
Copy link

Thanks for posting, looks like the pre-deploy linting script that was set up by "firebase init" is not behaving well. I'll have to debug further as to why that's happening on windows (I thought we had fixed it). In the meanwhile, you can just delete the following from firebase.json:

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

I deleted this and error is gone

@FortunatoHernandezJr
Copy link

Hola Tengo un problema con el firebase deploy
C:\ProyectosAngular_Fortunato\Angular Avanzado\goty-backend>firebase deploy

=== Deploying to 'firestore-grafica-fortunatoho'...

i deploying functions
Running command: npm --prefix %RESOURCE_DIR% run lint
Unknown command: "Avanzado\goty-backend\functions"

To see a list of supported npm commands, run:
npm help
node:events:491
throw er; // Unhandled 'error' event
^

Error: spawn npm --prefix C:\ProyectosAngular_Fortunato\Angular Avanzado\goty-backend\functions run lint ENOENT
at notFoundError (C:\Users\Fortunato JR\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)
at verifyENOENT (C:\Users\Fortunato JR\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\Fortunato JR\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 (node:internal/child_process:291:12)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess.cp.emit (C:\Users\Fortunato JR\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 (node:internal/child_process:291:12) {
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn npm --prefix C:\ProyectosAngular_Fortunato\Angular Avanzado\goty-backend\functions run lint',
path: 'npm --prefix C:\ProyectosAngular_Fortunato\Angular Avanzado\goty-backend\functions run lint',
spawnargs: []
}

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

@IngNex
Copy link

IngNex commented Oct 22, 2023

@FortunatoHernandezJr
hola tengo el mismo problema y tengo una semana querer solucionar y no eh podido, lo llegaste a solucionar.

@IngNex
Copy link

IngNex commented Oct 23, 2023

Me ayudo esta solución
en el archivo firebase.json

en el archivo firebase.json, --> borra "npm --prefix "$RESOURCE_DIR" run lint" esta línea desde aquí

...
"functions": {
"predeploy": [
"npm --prefix "$RESOURCE_DIR" run lint"
]
}

https://stackoverflow.com/questions/67763742/hello-i-am-getting-error-in-deploying-the-function-in-firebase-using-javascript

joehan pushed a commit that referenced this issue Apr 26, 2024
joehan pushed a commit that referenced this issue Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests