0

I am trying to install firebase functions so I can implement payment apis into my app.

Yet I am going through multiple tutorials and going through firebase manuals on how to install functions and get it working.

I am getting stuck here in terminal....

lukasbimba@Lukass-iMac functions % firebase deploy --only functions
(node:51250) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
  (Use `node --trace-warnings ...` to show where the warning was created).
⚠  functions: package.json indicates an outdated version of firebase-functions.
Please upgrade using npm install --save firebase-functions@latest in your functions directory.

=== Deploying to 'shoppeer-e7270'...

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

> functions@ lint /Users/lukasbimba/Desktop/Xcode Projects/ShopPeer/functions/functions
> eslint .

✔  functions: Finished running predeploy script.
i  functions: ensuring necessary APIs are enabled...

Error: HTTP Error: 404, Method not found.

 Having trouble? Try firebase deploy --help
lukasbimba@Lukass-iMac functions % 

index.js file

const functions = require('firebase-functions');

const admin = require('firebase-admin');

admin.initializeApp();

// // Create and Deploy Your First Cloud Functions
 https://firebase.google.com/docs/functions/write-firebase-functions

 exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send("Hello from Firebase!");
 });

// Take the text parameter passed to this HTTP endpoint and insert it into 
// Firestore under the path /messages/:documentId/original
exports.addMessage = functions.https.onRequest(async (req, res) => {
  // Grab the text parameter.
  const original = req.query.text;
  // Push the new message into Firestore using the Firebase Admin SDK.
  const writeResult = await admin.firestore().collection('messages').add({original: original});
  // Send back a message that we've successfully written the message
  res.json({result: `Message with ID: ${writeResult.id} added.`});
});

// Listens for new messages added to /messages/:documentId/original and creates an
// uppercase version of the message to /messages/:documentId/uppercase
exports.makeUppercase = functions.firestore.document('/messages/{documentId}')
    .onCreate((snap, context) => {
      // Grab the current value of what was written to Firestore.
      const original = snap.data().original;

      // Access the parameter `{documentId}` with `context.params`
      functions.logger.log('Uppercasing', context.params.documentId, original);
      
      const uppercase = original.toUpperCase();
      
      // You must return a Promise when performing asynchronous tasks inside a Functions such as
      // writing to Firestore.
      // Setting an 'uppercase' field in Firestore document returns a Promise.
      return snap.ref.set({uppercase}, {merge: true});
    });
  
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Lukas Bimba
  • 817
  • 14
  • 35
  • Without your Cloud Function code it will be difficult to help you. Also, you shoud update your `firebase-functions` package version, as indicated in the log. – Renaud Tarnec Jan 21 '21 at 12:49
  • Where could I access and show my cloud function code and I had just ran the update and am receiving the same error – Lukas Bimba Jan 21 '21 at 12:56
  • "Where could I access and show my cloud function code" => It is the code you wrote for defining the Cloud Function (by default it is in the `index.js` file). To show it, just edit your question and paste it. Of course if you have several hundreds of lines of code it makes no sense to paste it here!! In this case, please extract/make a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – Renaud Tarnec Jan 21 '21 at 12:59
  • I had added the index.js file – Lukas Bimba Jan 21 '21 at 13:03
  • At first sight I don't see any problem. Can you isolate the Cloud Function that creates the problem? Just deploy each Cloud Function as it was the only one in the `index.js`, file, e.g. comment out the two others. – Renaud Tarnec Jan 21 '21 at 13:32
  • See also that: https://stackoverflow.com/questions/63583106/get-http-error-404-method-not-found-when-running-firebase-deploy-only-fu. The first result of a google search with "functions: ensuring necessary APIs are enabled... Error: HTTP Error: 404, Method not found". – Renaud Tarnec Jan 21 '21 at 13:33
  • Also, as you read [here](https://firebase.google.com/docs/functions/get-started) in the doc, "It's a good practice to frequently update both the Firebase CLI and the SDK with these commands inside the functions folder of your Firebase project: `npm install firebase-functions@latest firebase-admin@latest --save` and `npm install -g firebase-tools`". – Renaud Tarnec Jan 21 '21 at 13:37
  • None of these solutions work so I am going to start the reinstallation process – Lukas Bimba Jan 22 '21 at 01:57
  • Where does it say that a cloud function is producing a problem from what I have provided? – Lukas Bimba Jan 22 '21 at 01:58
  • @LukasBimba there are a few other causes/solutions to the issue you are facing in this [community question](https://stackoverflow.com/questions/53049152/firebase-hosting-deploy-error-http-error-404-not-found), can you try those? – Ralemos Jan 22 '21 at 13:07
  • I have been trying all those solutions and still am having the same problem. Maybe I did not activate something on firebase? I am following tutorials and error still occurs. – Lukas Bimba Jan 24 '21 at 14:31
  • Can you share the code that is calling the functions that are not being found? – Ralemos Jan 27 '21 at 15:53

1 Answers1

1

running

curl -sL https://firebase.tools | bash

then running

curl -sL firebase.tools | upgrade=true bash

run this if your firebase versions are not saving

Lukas Bimba
  • 817
  • 14
  • 35