Petr
Petr

Reputation: 15

Angular2 + firebase-admin sdk

When i try to use firebase-admin SDK in my angular2 project i get this error

ERROR in ./~/firebase-admin/lib/auth/token-generator.js
Module not found: Error: Can't resolve 'jsonwebtoken' in '/home/koucky/git_projects/zlepsito-web/node_modules/firebase-admin/lib/auth'
 @ ./~/firebase-admin/lib/auth/token-generator.js 7:10-33
 @ ./~/firebase-admin/lib/auth/auth.js
 @ ./~/firebase-admin/lib/auth/register-auth.js
 @ ./~/firebase-admin/lib/index.js
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts

I installed firebase-admin via npm and in my app.module.ts i tryed to use it like this import 'firebase-admin' or var admin = require("firebase-admin"); both ways produce that error.

I have followed: https://firebase.google.com/docs/admin/setup

app.module.ts

var admin = require("firebase-admin");

var serviceAccount = require('./serviceAccountKey.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://myapp-99f41.firebaseio.com"
}); 

Does anyone know what to do, or is able to provide a snippet how to use firebase-admin SDK with angular2 project?

Thanks in advance

Upvotes: 0

Views: 1345

Answers (1)

ppoulsen
ppoulsen

Reputation: 61

I have a similar problem. Got one step further, but still not all the way.

Did a

npm install jsonwebtoken --save

which made the jsonwebtoken error disapear. Next error: missing 'dns', which was solved with:

npm install dns --save

Now i get an error saying 'Invalid left-hand side in assignment'.

I have used this method to call initializeApp instead of the key.json.

Upvotes: 1

Related Questions