1
votes

I'm trying to add a serviceAccountKey to my cloud functions project (Typescript)

var serviceAccount = require("/Users/kareldebedts/myAppName/functions/serviceAccountKeyName.json");

admin.initializeApp({
  storageBucket: "appName.appspot.com",
  credential: admin.credential.cert(serviceAccount),
});

When I deploy my functions I get this error:

Deployment error.
Function failed on loading user code. Error message: Code in file lib/index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module '/Users/kareldebedts/myAppName/functions/serviceAccountKeyName.json'

What Am I doing wrong? Because if i cmd click on the path it opens the file, so the path exists.

1

1 Answers

3
votes

You shouldn't use local file paths on your computer when writing Cloud Functions. It will only have available the files you deployed from your "functions" folder. So you should put the service account file in the functions folder along with your source code, and require it out of there with something like require('./serviceAccount.json').