Using Angular 2 with the firebase-admin sdk

Whenever I attempt to integrate the firebase-admin SDK into my Angular2 project, an error occurs:

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 have installed firebase-admin using npm and attempted two ways of importing it in my app.module.ts: import 'firebase-admin' or

var admin = require("firebase-admin");
. Unfortunately, both methods lead to the same error.

I have followed the guidelines provided at: https://firebase.google.com/docs/admin/setup

Here is a snippet from my 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"
}); 

If anyone knows how to resolve this issue or has a sample code snippet on integrating the firebase-admin SDK with an Angular2 project, please share. Thanks in advance!

Answer №1

Encountering a similar issue here. Managed to progress one step ahead, but the solution still eludes me.

Performed the following command:

npm install jsonwebtoken --save

This action resolved the jsonwebtoken error. However, I then encountered an issue with 'dns', which was remedied by executing:

npm install dns --save

Despite these fixes, a new error emerged stating 'Invalid left-hand side in assignment'.

I opted for the approach of calling initializeApp instead of using key.json.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the reason for the regeneration of the 2D array?

I have a method called generateWeights() that retrieves random values in an array; And a method named learn() that calls the changeWeights() method to alter the values in the array. Expected: Prior to invoking the learn() method, I anticipate receiving an ...

Unable to initialize default values on Form Load in Angular Reactive Forms

My goal is to make an HTTP request by passing an ID, then take the response and assign the values to form fields. I attempted using setValue and patchValue methods, but they did not yield the desired results. spService itemData = new ItemData() getIte ...

Displaying live, real-time information using ng-apexcharts

Is there a way to leverage the results of this loop: <div *ngFor="let hour of hours | async">{{ hour.messages }}</div> and incorporate it into the [series] of an Apex Chart? An attempt like this: <apx-chart *ngFor="let hour of hours | asyn ...

Issue with validating the date picker when updating user information

Trying to manage user accounts through a dialog form for adding and updating operations, where the type of operation is determined by a variable injected from the main component. Encountered an issue while launching the update process - the date picker tri ...

Import Information into Popup Window

When a user clicks on the "view" button, only the details of the corresponding challenge should be displayed: Currently, clicking on the "view" button loads all the challenges. This is because in my view-one-challenge.component.html, I have coded it as fo ...

transferring information seamlessly in Ionic using Angular router without the need for navigation

I have a list of names that are displayed, and when I click on any name in the list, it should take me to another page without actually navigating to that path. names.page.html: <ion-content> <ion-list *ngFor='let person of people'&g ...

Encountered an issue while attempting to assign a value to a property that is declared as [key in keyof T]

I am currently working on implementing a function that selects specific properties of an object. Here is the current function: const project = function<T>(object: T, projection: Projection<T>): Partial<T> { throw new Error("not imple ...

Incorrectly asserting the data type of a union

I am having trouble getting the type assertion to work in this specific scenario. Here is a Playground Link type Letter = "A" | "B" type Useless = {} type Container<T> = Useless | { type: "container" ...

Error in TypeScript React: 'Display' property is not compatible with index signature

My design page in React with TypeScript template is using Material UI, with custom styles implemented using the sx prop of Material UI. To customize the styling, I have created a separate object for the properties related to the sx props: const myStyles = ...

Developing a feature in Angular 4 where shared components generate new instances with each reload

My dashboard template is based on Core UI, but I have made some modifications to better suit my app. The template consists of modules, with the sidebar menu playing a crucial role in navigation. However, as my app is larger, I utilize the top menu for navi ...

How to properly create a Dockerfile using Node.js as the backend

Currently, I am developing a straightforward Angular application that relies on Node.js as the backend for file uploading. The structure of my project folder is shown below: To execute this setup in Angular, I follow these steps: Run 'ng ...

Steps for utilizing response data as parameters for useInfiniteQueryHere is how you can make

On the specific page where I am implementing useInfiniteQuery const { data, error, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage, status } = useInfiniteQuery( ['posts', searchState], ({ pageParam = 1 }) => post.search({ . ...

How come the inference mechanism selects the type from the last function in the intersection of functions?

type T = (() => 1) & (() => 2) extends () => infer R ? R : unknown What is the reason that T is not never (1 & 2)? Does the type always come from the last function, or can it come from one of them? ...

Unable to locate the reference to 'Handlebars' in the code

I am currently attempting to implement handlebars in Typescript, but I encountered an error. /// <reference path="../../../jquery.d.ts" /> /// <reference path="../../../require.d.ts" /> My issue lies in referencing the handlebars definition f ...

Where specifically in the code should I be looking for instances of undefined values?

One method in the codebase product$!: Observable<Product>; getProduct(): void { this.product$ = this.route.params .pipe( switchMap( params => { return this.productServ.getById(params['id']) })) } returns an ...

Guide on creating a Meteor Bootstrap WhatsApp clone

I'm currently going through the step-by-step guide for Whatsapp on the following website: After entering this command: meteor npm install angular@^1.5.8 --save I encountered the following message: no matches found: angular@^1.5.8 Does this mean t ...

What is the correct way to declare a variable with a generic type parameter?

Exploring the following code snippet that showcases a React component being defined with a type argument named TRow: function DataTable<TRow> ({ rows: TRow[] }) { return ( ) } Prior to this implementation, ES6 was utilized and components were c ...

Guide on Integrating RDLC Reports with Angular 7

I currently have a window application that contains multiple RDLC reports. As I am transitioning this window application to Angular 7, I am wondering if there is a way to utilize my existing RDLS reports in Angular 7? While I have come across suggestion ...

What is the best way to programmatically click on an element within the body of a webpage from an Angular component?

I am running a crisp chat service on my website and I am attempting to interact with the chat box from one of my component's typescript files. The chat box is represented as a div element with the id crisp-client inside the body tag. Can someone plea ...

Angular's recurring problem with reusable components

Exploring Angular's reusable components is new to me, and I am uncertain about how to effectively reuse the component once it has been created. In my project, I have three main components: parent, container, and reusable components. In 'parent.c ...