How to import react js file in electron main.js? - reactjs

I am using react and electron building an electron app.
I am new to react and electron and I got a problem on how to import a function in react index.js to electron main.js
Why I need to import that function to main.js file?
Because I need to pass the dependencies of my react app from main.js and most of these dependecies are function dependencies.
Here is the function in index.js which receive the dependencies. Look at the function dependency
mport React from 'react';
import ReactDOM from 'react-dom/client';
import './App.scss'
import './configFile'
import './fonts/NotoSansSC.otf'
import { init as initConfigFile } from './configFile'
import { init as initLanguage } from './international/language'
import App from './App';
export function dependency(config, saveConfigFile, createNewUser) {
}
const root = ReactDOM.createRoot(document.getElementById('root'))
initLanguage()
initConfigFile({
parentPwd: null,
qa: {
'configQuestion1': '123',
'configQuestion2': '123',
'configQuestion3': '123'
},
timeRangesNotAllowToUseTheComputer: [
],
language: 'en',
onlyWorkForTheUsers: ['test'],
usernames: ['onTheRoad', 'test'],
timeZones: { '中国': 'cn', '英国': 'uk' },
choosedTimeZone: 'uk'
}, null, null)
root.render(
<App />
)
Here is the main.js file
const path = require('path');
const { app, BrowserWindow } = require('electron');
const isDev = require('electron-is-dev');
function createWindow() {
// Create the browser window.
const win = new BrowserWindow({
width: 800,
height: 800,
webPreferences: {
nodeIntegration: true,
},
});
// and load the index.html of the app.
// win.loadFile("index.html");
win.loadURL(`file://${path.join(__dirname, '../build/index.html')}`);
// Open the DevTools.
if (isDev) {
win.webContents.openDevTools({ mode: 'detach' });
}
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(createWindow);
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bars to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
I tried to import the file use require
const index = require('./index.js')
when I build the react app there is no error throwed but when I start the electron with electron . got error like this:
A JavaScript error occurred in the main process
Uncaught Exception:
/home/zxw/Desktop/bsd/src/index.js:1
import React from 'react';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1040:15)
at Module._compile (node:internal/modules/cjs/loader:1076:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1175:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:829:12)
at c._load (node:electron/js2c/asar_bundle:5:13339)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/home/zxw/Desktop/bsd/public/main.js:4:15)
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
And then I tried to load the function by import statement like below
import {dependency} from '../src/index'
When I build react app there is no error throwed but when I start the electron app I got error like this
A JavaScript error occurred in the main process
Uncaught Exception:
/home/zxw/Desktop/bsd/public/main.js:4
import {dependency} from '../src/index'
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1040:15)
at Module._compile (node:internal/modules/cjs/loader:1076:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1175:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:829:12)
at c._load (node:electron/js2c/asar_bundle:5:13339)
at loadApplicationPackage (/home/zxw/Desktop/bsd/node_modules/electron/dist/resources/default_app.asar/main.js:121:16)
at Object.<anonymous> (/home/zxw/Desktop/bsd/node_modules/electron/dist/resources/default_app.asar/main.js:233:9)
at Module._compile (node:internal/modules/cjs/loader:1120:14)
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
Is there is a way to pass the dependencies to the index.js from main.js ?

I fix it by throgh a dump way
First install the axios and the express
Then in the react src file add a file called appDependency
Here is the code
import axios from 'axios'
export function saveConfigFile(config) {
try {
axios.put('http://localhost:8888/config', config).then(response => {
if (response.status !== 200) {
throw response.data
}
})
} catch (e) {
console.error(`Error occrred while saving the config file: ${e}`)
throw e
}
}
export function createNewUser(username, pwd) {
try {
axios.post('http://localhost:8888/users', {
username: username,
pwd: pwd
}).then((response) => {
if (response.status !== 200) {
throw response.data
}
})
} catch (e) {
console.error(`Error occrred while creating new user. ${e}`)
throw e
}
}
async function fetchTheConfig() {
return await axios.get('http://localhost:8888/config').then((response) => {
console.log(`The response is ${JSON.stringify(response.data)}`)
if (response.status !== 200) {
throw response.data
} else {
return response.data
}
})
}
export function getConfigFile() {
try {
return fetchTheConfig()
} catch (e) {
console.error(`err occurred while fetching the config file. ${e}`)
throw e
}
}
And in the electron main.js file I use express created a server
const path = require('path');
const { app, BrowserWindow } = require('electron');
const express = require('express')
const exApp = express()
exApp.use(express.urlencoded())
exApp.use(express.json())
const config = {
parentPwd: null,
qa: {
'configQuestion1': '123',
'configQuestion2': '123',
'configQuestion3': '123'
},
timeRangesNotAllowToUseTheComputer: [
],
language: 'en',
onlyWorkForTheUsers: ['test'],
usernames: ['onTheRoad', 'test'],
timeZones: { '中国': 'cn', '英国': 'uk' },
choosedTimeZone: 'uk'
}
function configFile(req, res) {
console.log(`request received getConfigFile`)
res.status(200).send(config)
}
function saveConfigFile(req, res) {
console.log(`The body is ${req.body.timeRangesNotAllowToUseTheComputer}`)
res.status(200).send()
}
function createNewUser(req, res) {
console.log(`The req is `)
}
function appDependecys() {
exApp.get('/config', configFile)
exApp.put('/config', saveConfigFile)
exApp.post('/users', createNewUser)
exApp.listen(8888)
}
appDependecys()
In the react index.js I made the change to
import React from 'react';
import ReactDOM from 'react-dom/client';
import './App.scss'
import './configFile'
import './fonts/NotoSansSC.otf'
import { init as initConfigFile } from './configFile'
import { init as initLanguage } from './international/language'
import App from './App';
import { getConfigFile, saveConfigFile, createNewUser } from './appDependency'
const root = ReactDOM.createRoot(document.getElementById('root'))
getConfigFile().then((cfg) => {
console.log(`The fucking config is ${cfg}`)
initLanguage()
initConfigFile(cfg, saveConfigFile, createNewUser)
root.render(
<App />
)
})

Related

Firebase cloud messaging: Cannot receive notification in React-js

Firebase version: 9.6.6
firebase-messaging.js - inside a src folder
import firebase from "firebase/compat";
import "firebase/messaging";
const firebaseConfig = {
//api
};
firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();
export const requestForToken = async () => {
const swRegistration = await navigator.serviceWorker.register(`${process.env.PUBLIC_URL}/firebase-messaging-sw.js`);
const token = await messaging.getToken({
serviceWorkerRegistration: swRegistration,
});
return token;
};
export const onMessageListener = () =>
new Promise((resolve) => {
messaging.onMessage((payload) => {
resolve(payload);
});
});
firebase-messaging-sw.js - inside a public folder
import { initializeApp } from "firebase/app";
import { getMessaging } from "firebase/messaging/sw";
const firebaseApp = initializeApp({
//api
});
const messaging = getMessaging(firebaseApp);
Inside App.js
useEffect(()=> {
if (!fcm_token) {
requestForToken()
.then(r => {
console.log("token: ", r);
dispatch(setFCMToken(r));
})
.catch(error => {
console.log("error while receiver fcm token from firebase: ", error)
});
} else {
console.log("fcm token: ", fcm_token);
}
}, [])
onMessageListener()
.then(value => console.log("notification msg: ", value))
.catch(err => console.log("error: ", err))
When I run the project
Failed to register a ServiceWorker for scope ('http://localhost:3000/build/')
with script ('http://localhost:3000/build/firebase-messaging-sw.js'):
ServiceWorker script evaluation failed
this error shows up, even though the code is correct according to documentation.
Error persists even if I change the way I import inside firebase-messaging-sw.js file to "importScripts(' ')".
Only after removing everything in firebase-messaging-sw.js file, that error do not show up and I can receive the FCM token.
However, when I send test messages from firebase console to FCM token received in my react app, no messages are showing up in console.
Question: How should I change my code to be able to receive notifications and show them in console or as a notification in browser.
If you're using latest version there is alittle bit modifications in registering service worker file, this is complete process of notification configuration
register service worker as below in your service worker file:
export const registerServiceWorker = () => {
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('firebase-messaging-sw.js')
.then(function (registration) {
return registration.scope;
})
.catch(function (err) {
return err;
});
}
};
import service worker, and call function in your index.js File:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import { registerServiceWorker } from './serviceWorker';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
registerServiceWorker();
After this configuration, you will see fire base notification in console, and if firebase-messaging.js file is configured well with no error, your feature will work

Next.js imported function errors out with 'ReferenceError' in getServerSideProps

I am using Firebase for auth in my project. After user authenticates, I set his/her id token in cookies, so that next time any request is made to auth-only page, I can verify the token server-side for SSR.
However, the wrapper function I wrote for this errors out as 'ReferenceError' when used in getServerSideProps.
lib/firebase-admin.ts
import { initializeApp, App, AppOptions } from 'firebase-admin/app'
import { getAuth, Auth } from 'firebase-admin/auth'
import { credential } from 'firebase-admin'
import serviceAccount from '../secrets/firebase-admin-sdk.json'
// Firebase Admin app configs
const firebaseAdminConfig: AppOptions = {
credential: credential.cert(JSON.stringify(serviceAccount))
}
// Get app admin instance and export it
const app: App = initializeApp(firebaseAdminConfig)
export default app
// Get auth admin and export
export const auth: Auth = getAuth(app)
utils/auth-server.ts
import { auth } from '../lib/firebase-admin'
import { DecodedIdToken } from 'firebase-admin/auth'
import AuthErrorMessages from '../constants/auth'
// Export function to verify id token in server side
interface IVerifyIdToken {
status: boolean
message?: string
token?: DecodedIdToken
}
export const verifyIdToken = async (idToken: string): Promise<IVerifyIdToken> => {
try {
const decodedIdtoken = await auth.verifyIdToken(idToken, true)
console.log(decodedIdtoken)
return { status: true, token: decodedIdtoken }
} catch (e) {
return { status: false, message: e }
}
}
components/test.tsx
import { GetServerSideProps, GetServerSidePropsContext, InferGetServerSidePropsType } from 'next'
import nookies from 'nookies'
import { verifyIdToken } from '../utils/auth-server'
export const getServerSideProps: GetServerSideProps = async (ctx: GetServerSidePropsContext) => {
const cookies = nookies.get(ctx)
if (cookies.token) {
const idToken = await verifyIdToken(cookies.token) // ERROR HERE
console.log(idToken)
return {
props: {
email: 'DUMMY'
}
}
} else {
return {
props: {
email: "NO EMAIL (not logged in)"
}
}
}
}
export default function Test({ email }: InferGetServerSidePropsType<typeof getServerSideProps>) {
return (
<p>Your email: {email}</p>
)
}
Error while opening /test
ReferenceError: Cannot access 'auth' before initialization
at Module.auth (webpack-internal:///./lib/firebase-admin.ts:5:53)
at verifyIdToken (webpack-internal:///./utils/auth-server.ts:12:87)
at getServerSideProps (webpack-internal:///./pages/test.tsx:20:96)
at Object.renderToHTML (/home/captain-woof/Desktop/charity-cms/node_modules/next/dist/server/render.js:479:26)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async doRender (/home/captain-woof/Desktop/charity-cms/node_modules/next/dist/server/next-server.js:1392:38)
at async /home/captain-woof/Desktop/charity-cms/node_modules/next/dist/server/next-server.js:1487:28
at async /home/captain-woof/Desktop/charity-cms/node_modules/next/dist/server/response-cache.js:63:36
I fixed the problem! (thanks #ArneHugo the hint)
So, what happened was not really a cyclic dependency, but files getting compiled asynchronously, because of which there was no actual control over what got compiled first.
I fixed this by making a small change:
lib/firebase-admin.ts
.
.
.
const serviceAccount = require('../secrets/firebase-admin-sdk.json') // Earlier -> import serviceAccount from '../secrets/firebase-admin-sdk.json'
.
.
.
credential: credential.cert(serviceAccount) // Earlier -> credential: credential.cert(JSON.stringify(serviceAccount))
.
.
.
// REPLACE ENTIRE BELOW PORTION WITH THIS
// Get app admin instance and export it
if (getApps().length === 0) { // To make sure only one instance is created and referred to at a time
initializeApp(firebaseAdminConfig)
}
// Get auth admin and export
export const auth: Auth = getAuth(getApp()) // To make sure auth from only the one app instance we have is exported

React Jest TypeError: Cannot read property 'baseUrl' of undefined

I have a simple login api call where the base url is in config file, code below
api.js
export const login = (username, password) => {
Axios.post(`${config.loginApi.baseUrl}/login`, {
username,
password
})
.then(res => res)
.catch(e => e);
};
I wrote the test case(s) below,
api.test.js
import axios from 'axios';
import { login } from './api';
import MockAdapter from 'axios-mock-adapter';
import config from 'config';
describe('signin signup Api', () => {
afterEach(() => {
jest.restoreAllMocks();
});
it('logs in successfully', (done) => {
const mock = new MockAdapter(axios);
mock.onGet(`${config.loginApi.baseUrl}/login`).reply(200, { data: '1234abcd' });
login('dee#gmail.com', 'test').then((res)=>{
expect(res).toEqual('1234abcd');
done();
});
});
or the other test case I wrote earlier
import axios from 'axios';
import { login } from './api';
import config from 'config';
jest.mock('axios');
it('logs in successfully', async () => {
axios.post.mockImplementationOnce(() => Promise.resolve({ data: '1234abcd' }));
await expect(login('dee#gmail.com', 'test')).resolves.toEqual('1234abcd');
});
I researched and found this post close to my issue. But in all the cases I'm getting
TypeError: Cannot read property 'baseUrl' of undefined
Why is this not able to know the baseUrl?
I tried mocking the config,
jest.mock(config);
got TypeError: moduleName.split is not a function.
Please suggest a fix/workaround.
Adding more info on the config
in config folder, I have
require('dotenv').config();
module.exports = config;
in development environment, it will pick this config from dev.js, in prod - prod.js and so on
in public folder, dev.js file I have
loginApi: {
baseUrl: 'https://abcd.com',
mocks: true,
mockDelay: 2000
}
I found the fix for this issue,
in the setupTests.js, I added
global.config ={
loginApi: {
baseUrl: 'https://abcd.com',
mocks: true,
mockDelay: 2000
}
}
This fixed that TypeError: Cannot read property 'baseUrl' of undefined issue.

How can I setup an Apollo client in React for both upload and subscriptions?

I would like to set up a graphql client with React for both uploading file and handle subscriptions from a graphql server.
The file upload and the other queries work well. The problem is with subscriptions. I get in the browser console the following error:
WebSocket connection to 'ws://localhost:3001/subscriptions' failed: Connection closed before receiving a handshake response
I have used apollo-upload-client for file upload and apollo-link-ws for subscriptions.
I can see that subscriptions-transport-ws suggests using createNetworkInterface and addGraphQLSubscriptions but this approach is not compatible with apollo-upload-client that only supports createUploadLink.
I'm stuck. Please help.
I setup my client like this:
import React from 'react';
import ApolloClient from 'apollo-client';
import { ApolloProvider } from 'react-apollo';
import { createUploadLink } from 'apollo-upload-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloLink, Observable, split } from 'apollo-link';
import { WebSocketLink } from 'apollo-link-ws';
import { getMainDefinition } from 'apollo-utilities';
const cache = new InMemoryCache();
const request = async (operation) => {
const token = localStorage.getItem('token');
operation.setContext({
headers: {
authorization: token ? `Bearer ${token}` : '',
},
});
};
const httpLink = createUploadLink({ uri: 'http://localhost:3001/graphql' });
// Create a WebSocket link:
const wsLink = new WebSocketLink({
uri: 'ws://localhost:3001/subscriptions',
options: {
reconnect: true
},
});
// using the ability to split links, you can send data to each link
// depending on what kind of operation is being sent
const link = split(
// split based on operation type
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === 'OperationDefinition' && operation === 'subscription';
},
wsLink,
httpLink,
);
const requestLink = new ApolloLink((operation, forward) =>
new Observable((observer) => {
let handle;
Promise.resolve(operation)
.then(oper => request(oper))
.then(() => {
handle = forward(operation).subscribe({
next: observer.next.bind(observer),
error: observer.error.bind(observer),
complete: observer.complete.bind(observer),
});
})
.catch(observer.error.bind(observer));
return () => {
if (handle) handle.unsubscribe();
};
}));
const apolloClient = new ApolloClient({
link: ApolloLink.from([
requestLink,
link,
]),
cache,
});
export const withApolloClient = App => (
<ApolloProvider client={apolloClient}>
<App client={apolloClient} />
</ApolloProvider>
);
export default apolloClient;
I am using a similar config but instead of importing WebSocketLink from apollo-link-ws I imported it from #apollo/client.
With that setup i had both the subscription and upload working.
import { WebSocketLink } from "#apollo/client/link/ws";
I would suggest to use graphql-server-express like this

Unable run isomorphic single page app on firebase with ES6

I have an isomorphic react app. It has a server.js file inside app/src/ directory.
Server.js
import path from 'path';
import express from 'express';
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';
import expressJwt, { UnauthorizedError as Jwt401Error } from 'express-jwt';
import nodeFetch from 'node-fetch';
import React from 'react';
import ReactDOM from 'react-dom/server';
import PrettyError from 'pretty-error';
import App from './components/App';
import Html from './components/Html';
import { ErrorPageWithoutStyle } from './routes/error/ErrorPage';
import errorPageStyle from './routes/error/ErrorPage.css';
import createFetch from './createFetch';
import router from './router';
import assets from './assets.json'; // eslint-disable-line import/no-unresolved
import configureStore from './store/configureStore';
import { setRuntimeVariable } from './actions/runtime';
import config from './config';
const app = express();
//
// Tell any CSS tooling (such as Material UI) to use all vendor prefixes if the
// user agent is not known.
// -----------------------------------------------------------------------------
global.navigator = global.navigator || {};
global.navigator.userAgent = global.navigator.userAgent || 'all';
//
// Register Node.js middleware
// -----------------------------------------------------------------------------
app.use(express.static(path.resolve(__dirname, 'public')));
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
//
// Authentication
// -----------------------------------------------------------------------------
app.use(
expressJwt({
secret: config.auth.jwt.secret,
credentialsRequired: false,
getToken: req => req.cookies.id_token,
}),
);
// Error handler for express-jwt
app.use((err, req, res, next) => {
// eslint-disable-line no-unused-vars
if (err instanceof Jwt401Error) {
console.error('[express-jwt-error]', req.cookies.id_token);
// `clearCookie`, otherwise user can't use web-app until cookie expires
res.clearCookie('id_token');
}
next(err);
});
if (__DEV__) {
app.enable('trust proxy');
}
//
// Register server-side rendering middleware
// -----------------------------------------------------------------------------
app.get('*', async (req, res, next) => {
try {
const css = new Set();
// Universal HTTP client
const fetch = createFetch(nodeFetch, {
baseUrl: config.api.serverUrl,
cookie: req.headers.cookie,
});
const initialState = {
user: req.user || null,
};
const store = configureStore(initialState, {
fetch,
// I should not use `history` on server.. but how I do redirection? follow universal-router
});
store.dispatch(
setRuntimeVariable({
name: 'initialNow',
value: Date.now(),
}),
);
// Global (context) variables that can be easily accessed from any React component
// https://facebook.github.io/react/docs/context.html
const context = {
// Enables critical path CSS rendering
// https://github.com/kriasoft/isomorphic-style-loader
insertCss: (...styles) => {
// eslint-disable-next-line no-underscore-dangle
styles.forEach(style => css.add(style._getCss()));
},
fetch,
// You can access redux through react-redux connect
store,
storeSubscription: null,
};
const route = await router.resolve({
...context,
pathname: req.path,
query: req.query,
});
if (route.redirect) {
res.redirect(route.status || 302, route.redirect);
return;
}
const data = { ...route };
data.children = ReactDOM.renderToString(
<App context={context} store={store}>
{route.component}
</App>,
);
data.styles = [{ id: 'css', cssText: [...css].join('') }];
data.scripts = [assets.vendor.js];
if (route.chunks) {
data.scripts.push(...route.chunks.map(chunk => assets[chunk].js));
}
data.scripts.push(assets.client.js);
data.app = {
apiUrl: config.api.clientUrl,
state: context.store.getState(),
};
const html = ReactDOM.renderToStaticMarkup(<Html {...data} />);
res.status(route.status || 200);
res.send(`<!doctype html>${html}`);
} catch (err) {
next(err);
}
});
//
// Error handling
// -----------------------------------------------------------------------------
const pe = new PrettyError();
pe.skipNodeFiles();
pe.skipPackage('express');
// eslint-disable-next-line no-unused-vars
app.use((err, req, res, next) => {
console.error(pe.render(err));
const html = ReactDOM.renderToStaticMarkup(
<Html
title="Internal Server Error"
description={err.message}
styles={[{ id: 'css', cssText: errorPageStyle._getCss() }]} // eslint-disable-line no-underscore-dangle
>
{ReactDOM.renderToString(<ErrorPageWithoutStyle error={err} />)}
</Html>,
);
res.status(err.status || 500);
res.send(`<!doctype html>${html}`);
});
//
// Launch the server
// -----------------------------------------------------------------------------
if (!module.hot) {
app.listen(config.port, () => {
console.info(`The server is running at http://localhost:${config.port}/`);
});
}
//
// Hot Module Replacement
// -----------------------------------------------------------------------------
if (module.hot) {
app.hot = module.hot;
module.hot.accept('./router');
}
export default app;
I want to deploy my app using firebase. For that I have setup firebase.json like so -
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"function": "app"
}
]
}
}
where app is a firebase function defined inside app/functions/ i.e. src and functions have same parent directory.
Functions directory has node_modules, properly configured and its working when tested for other functions.
Problem -
My index.js file inside app/functions is like so -
import app from '../src/server';
import functions from 'firebase-functions';
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
// exports.helloWorld = functions.https.onRequest((request, response) => {
// response.send("Hello from Firebase!");
// });
exports.app = functions.https.onRequest(app);
Firebase is complaining that it doesnt support ES6. How do I get this function to work with ES6? I cannot simply change functions/index.js file to ES5 and hope things will work as when requires are resolved, they'd expect everything inside to be ES5 as well which is not the case as my entire codebase is in ES6.
I found the solution to this problem.
Make a directory in functions/ say 'build'.
Build your project
Copy all the contents of your ./dist or ./build (wherever your build files are present) to functions/build
Modify functions/index.js as follows -
const app = require('./build/bundle.js').default;
const functions = require('firebase-functions');
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
// exports.helloWorld = functions.https.onRequest((request, response) => {
// response.send("Hello from Firebase!");
// });
exports.app = functions.https.onRequest(app);
Works like a charm

Resources