firebase CLI will not recognize current directory for 'firebase init'

16,586

Solution 1

  1. Got to folder:

    /Users/Username/

  2. Search for a file with name of firebase.json and Delete it.

  3. Reinstall firebase tool with this command (--unsafeper- to avoid permissions error messages & use sudo):

    $ sudo npm install --unsafeper- -g firebase-tools

  4. Then, go to your pubilc folder (you have to create one) which contains your HTML, JS, images and CSS files and use this command:

    $ sudo firebase init

    $ sudo firebase deploy

  5. The reset is easy and as mentioned in the firebase docs:

https://firebase.google.com/docs/hosting/quickstart

Solution 2

The reason is that you must have initiliazed a project in some parent directory (of this myProject folder) in the past. Somehow firebase sees that project in that directory rather than initializing a new project in the current path.

Solution: Check the parent directories of the path where you want to initialize a firebase project now. Delete / Move the firebase files from that folder and then you should be able to initialize a project in the current directory.

For example:

I also faced the same problem. I was trying to initialize a project in this path:

D:\Work\Projects\myProject

But somehow it always got initialized in this path:

D:\Work

After some searching it turned out that the reason was that I had initialized a project in D:\Work directory. I moved those files to another folder and that solved the problem.

Solution 3

I was also facing this problem and windows not able to recognize the firebase. I don't know the exact reason why it was behaving in such a manner but it solved the problem.

1) I installed the firebase-tools using a command on command prompt

npm install -g firebase-tools

and it didn't work. 2) I restarted the machine. 3) then again I executed the same command from step 1) npm install -g firebase-tools and it worked.

Share:
16,586
WillD
Author by

WillD

Updated on June 13, 2022

Comments

  • WillD
    WillD almost 2 years

    I am following a tutorial on Ionic Angular and it has come to the point where the instructor is having me publish my code to Firebase Hosting. First I used NPM to install the Firebase CLI. Then I was instructed to use the firebase init command. The issue is that the CLI doesn't seem to recognize the current directory that is selected in my terminal.

    I run: cd /Users/MyUserName/myProjectsFolder/myProject/ Then I run firebase init and it displays:

    You're about to initialize a Firebase project in this directory:

    /Users/MyUserName

    When I would expect it to read:

    You're about to initialize a Firebase project in this directory:

    /Users/MyUserName/myProjectsFolder/myProject

    A little bit of googling found this page: https://firebase.google.com/docs/cli/

    Which includes this passage:

    To initialize a new project directory, change directories in the terminal to your desired project directory and run: firebase init

    Based on this I would expect the steps I took to work.

    I am confused. Has anyone ever run into this behavior? Can anyone think of a way to get the CLI to function as expected?

    Thanks.