colinskow / angular-electron-dream-starter

:tada: An Angular Electron Starter kit featuring Webpack, Angular 4 (Router, Http, Forms, Services, ngrx, Tests, E2E, Coverage), Karma, Spectron, Jasmine, Istanbul, and TypeScript
MIT License
162 stars 54 forks source link

'firebase-admin' npm package throws an error. #27

Closed debuggerpk closed 6 years ago

debuggerpk commented 6 years ago

Note: for support questions, please use one of these channels: Chat: AngularClass.slack or Twitter: @AngularClass

I believe this is a bug

This is a bug report, i believe webpack build for main.electron.ts does not loads json files properly.

I am trying to run the firebase-admin inside electron (not the web part). When it do

import * as firebase from 'firebase-admin';
import { default as config } from './firebase-config';

firebase.initializeApp({
  credential: firebase.credential.cert(config),
  databaseURL: 'https://***.firebaseio.com'
});

the firebase-admin is running fine, but along the way, it throws an error first.

ERROR in [at-loader] ./src/electron/nest/firebase-config.ts:2:3
    TS2345: Argument of type '{ "type": string; "project_id": string; "private_key_id": string; "private_key": string; "client_...' is not assignable to parameter of type 'string | ServiceAccount'.
  Object literal may only specify known properties, and '"type"' does not exist in type 'string | ServiceAccount'.

As you can see, i have rename the certificate file from a ".json" to ".ts", and modified the certificate file to have

export default {
}

it is because json does not loads propely, something to do with tsconfig or webpack config?.

PS: To make it run alright, i had to add this to my environment settings before installing packages, to make the binaries build them from source.

PPS: for everybody else, please note that you must have python2 available when building packages. If you have python3 as default, just make sure path to python2 is in your path.

export npm_config_target=1.7.9
# The architecture of Electron, can be ia32 or x64.
export npm_config_arch=x64
export npm_config_target_arch=x64
# Download headers for Electron.
export npm_config_disturl=https://atom.io/download/electron
# Tell node-pre-gyp that we are building for Electron.
export npm_config_runtime=electron
# Tell node-pre-gyp to build module from source code.
export npm_config_build_from_source=true
debuggerpk commented 6 years ago

just verified, the firebase admin works fine with nestjs and electron, its only this package.

colinskow commented 6 years ago

The best way to load the Firebase certificate is with the Webpack JSON Loader. It is kind of dirty to hack it with TypeScript.

Also make sure firebase-admin is a DEPENDENCY rather than devDependency in your package.json. You shouldn't need special environment variables to build the native dependencies. Just run npm run install-app-deps and this should automatically build everything for your current platform and Electron version. (And this is also run automatically after you NPM install.)

colinskow commented 6 years ago

This is already explained in the README if you dig in.

debuggerpk commented 6 years ago

@colinskow yep, did read the README, however grpc prebuilt binary is not available for electron version in this repo, thus had to build that package from source.

having said that, i think the error

ERROR in [at-loader]

is with awesome-typescript-loader and type checking. will verify it by disabling type checking for webpack configuration for electron.

PS: it is a non blocking error during development, because after throwing the error, firebase responds. however, during the build process, the build process exits.

debuggerpk commented 6 years ago

yep, doing

{
  "transpileOnly": true
}

takes care of the errors. Thanks for this awesome loader btw. Will work to have three tssconfig.json files.