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

Fails when used as a module #464

Closed
samtstern opened this issue Sep 19, 2017 · 6 comments
Closed

Fails when used as a module #464

samtstern opened this issue Sep 19, 2017 · 6 comments
Assignees

Comments

@samtstern
Copy link
Contributor

samtstern commented Sep 19, 2017

Version info

$ firebase --version
3.12.0

Steps to reproduce

Create a functions index.js file that looks like this:

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

// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
exports.helloWorld = functions.https.onRequest((request, response) => {
  // ...
});

Then try to run firebase deploy

Expected behavior

Function initializes

Actual behavior

Error: Error occurred while parsing your function triggers.

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.resolve (path.js:1146:7)
    at Object.<anonymous> (/tmp/fbfn_774738B960wvGSj3D/node_modules/firebase-tools/lib/ensureDefaultCredentials.js:18:34)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
@samtstern
Copy link
Contributor Author

cc @mbleigh

@mitulgolakiya
Copy link

mitulgolakiya commented Sep 29, 2018

@samtstern @mbleigh I'm still getting this error. any idea how to fix it?

firebase --version
4.2.1

node --version
v8.12.0

firebase-admin
5.12.0

firebase-functions
2.0.2

I am using Windows 10 64 Bit.

@ghost
Copy link

ghost commented Dec 5, 2018

@mitulgolakiya @samtstern @mbleigh

Has anyone found a solution to this issue? I am also having the same problem and there is not a lot of solutions about this. I am on MacOS HighSierra

firebase --version
6.1.1

node --version
v8.11.4

firebase-admin
6.0.0

firebase-functions
2.1.0

google-cloud/storage
2.3.1

@mitulgolakiya
Copy link

mitulgolakiya commented Dec 5, 2018

@fabienthiombiano Actually, I was not able to figure out the problem. The main project was set up by a developer who was using Mac and I was on trying this thing to re-deploy with some changes from Windows. But when I tried it on a Mac, it worked.

But since you are already on Mac, so not sure what can be a problem. Just uninstall firebase, delete node modules cache and try again. Or try to setup it on some fresh Mac. I used MacOS HighSierra only.

@bkendall
Copy link
Contributor

bkendall commented Dec 5, 2018

If you are seeing this issue, please open a new issue with your steps to reproduce the issue and the appropriate logs. Thank you.

@ghost
Copy link

ghost commented Dec 5, 2018

Thanks @mitulgolakiya and @bkendall. As per your advice, below is the steps to reproduce. Just a basic image upload function and the error code from firebase

version info
firebase --version 6.1.1

index.js file in functions folder

const functions = require('firebase-functions');
const os = require('os');
const path = require('path');
const { Storage } = require('@google-cloud/storage');

const gcs = new Storage ({

});
exports.onImageUpload = functions.storage.object().onFinalize(event => {
console.log(event);

const fileBucket = event.bucket;
const contentType = event.ContentType;
const filePath = event.filePath;
console.log('file changes detected!');

const destBucket = gcs.bucket(fileBucket);
const tmpFilePath = path.join(os.tmpdir(), path.basename(filePath)); 
filename
const metaData = {
    contentType: contentType
};

return destBucket.file(filePath).download({
    destination : tmpFilePath, 
}).then(() => {
    console.log("Image downloaded to the local destination");
    destBucket.file(filePath).upload({
        destination: "renamed-" + path.basename(filePath), 
        metaData: metaData
    });
});
});

error code firebase

  `TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.basename (path.js:1361:5)
    at exports.onImageUpload.functions.storage.bucket.object.onFinalize.event           (/user_code/index.js:30:53)
    at cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:105:23)
    at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:135:20)
    at /var/tmp/worker/worker.js:768:24
   at process._tickDomainCallback (internal/process/next_tick.js:135:7)`

Edit: Just opened a new issue ticket as indicated. Thanks

@firebase firebase locked as resolved and limited conversation to collaborators Dec 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants