using firebase-admin in netlify function - node.js

I am trying to use firebase-admin npm module in a Netlify cloud function. By default netlify-lambda packages the functions with Webpack, which breaks firebase-admin as it's not compatible with Webpack.
I tried using the alternate "zip n ship" method but even that doesn't works. From the error, it seems the node_modules generated on my machine are not working correctly on the machine where the function is deployed. Here is the error:
Error: The gRPC binary module was not installed. This may be fixed by running "npm rebuild"
Original error: Cannot find module '/var/task/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64-glibc/grpc_node.node'
Anyone who has made this work?

you can use Webpack to generate new package.json file into the lambda directory and install its dependencies, then run netlify-lambda as this tutorial shows firebase-admin-with-netlify-lambda

Related

google-auth-library has missing dependencies when installed

I am trying to use google-auth-library with a react app but am getting various errors which seem to indicate missing dependencies. The errors are all in a format similar to this:
Module not found: Error: Can't resolve 'buffer' in '/private/tmp/minimal-example/node_modules/buffer-equal-constant-time'
The error messages include details on how to add a polyfill for the missing dependencies, but even after going through and adding all these polyfills I am unable to use the library. The logs for the development server still show errors for missing files, and the browser console has the following error:
GET http://metadata.google.internal./computeMetadata/v1/instance net::ERR_NAME_NOT_RESOLVED
Steps to reproduce:
Install Node 16.13.2
Create a react app npx create-react-app minimal-example
Enter directory for the created project cd minimal-example
Install google-auth-library npm install google-auth-library --save
Add the following code to ./src/App.js
const {GoogleAuth} = require('google-auth-library');
Start the development server npm start
Observe errors
What am I doing wrong?
I Have the same problem with same google-auth-library package!
This is a problem with using webpack 5 on React scripts=> v5
Have three solutions to resolve:
downgrade react-scripts to version 4.0.3. on package.json file.
Overwrite the config webpack config, but, i will need install react-app-rewired to do this, because react app not have webpack.config on tree app files.
you can eject the script to root folder executing npm run eject, but caution, this action is permanent, more here: https://stackoverflow.com/a/48395890
Some people answered this problem in How to Polyfill node core modules in webpack 5
and https://github.com/facebook/create-react-app/issues/12072

using lovell/sharp with angular project

I'm trying to use lovell/sharp with Angular universal project, but I have an issue.
I build the server part via webpack and I added sharp to webpack's externals, but I got this error Unexpected character '�' (1:2)
so, I added node-loader to webpack, it builds the project and generates dist folder that contains main.js and sharp-*.node files
but when I run node dist/main I got this error:
Error:
Something went wrong installing the "sharp" module
node-loader:
Error: The specified module could not be found.
//sharp-ac5709806d227d1d966f7f0b76814d78.node
minimal reproduction:
https://github.com/eng-dibo/ng-sharp-issue
1- install dependencies npm install
2- build the server npm run build:server:dev
3- serve node dist/main
to check the webpack configurations, check this file './webpack.server.config.js`
issue solved
the problem is that the webpack plugin webpack-node-externals cannot work with monorepos, in this case it fails to get the correct path of package.json file, results in node modules don't be excluded.

React Native: Unable to resolve a local module. Exists in Node Modules

I'm working on an app that both has a website (React) and mobile app (React Native). In one repository I have my web, mobile and redux files which is my local module/package (so that they can be shared). I have not had any problems with installing my local package when working on web. However with React Native I am running into issues with the package.
I ran
npm install --save '../store/sagas
Which gave me
Unable to resolve "redux-saga-store/sagas/index.js" from "App.js"
Fair. App.js is where I am calling my rootSaga via
import rootSaga from 'redux-saga-store/sagas/index.js';
Which is identical to how web is calling the same file.
I checked my node_modules and the package and all the expected files are there. I tried
npm list
Which returned (as expected)
redux-saga-store#1.0.0 -> /Users/{myname}/Repos/{repositoryname}/shared/store
I have triple-checked the paths and they are correct.
I tried npm install with the global flag. I went on to nuking my node_modules and package-lock.json so I could try re-installing. I created a brand new react-native app using create-react-native-app which also did not fix the issue. I would really appreciate any suggestions or help

Nodejs application (Developed using typescrpt not in javascript) deployment issue on Firebase using "firebase serve" command

Trying to deploy nodejs API on google cloud i.e. firebase and getting following error.
Steps :
ran tsc src\index inside functions folder for compiling typescript file.
Ran "firebase serve" (Error 1)also tried "firebase serve --only functions,hosting" (Error 2)
Getting following error
Tried multiple time with installation of typescript using npm install typescript as well as npm install -g typescript prior to compile and deploy. but still getting same error. Please find the attachment of the folder structure of my project. Hence I have explicitly moved .vscode folder and its file inside functions folder.
It has been resolved. I have one missing package that is tslint. So I followed below steps and it has fixed this issue. It was pretty silly one -
npm install tslint
npm run build
Build will provides all warning and error and I made corresponding changes in package.json.
for more reference find the firebase doc link -
https://firebase.google.com/docs/functions/typescript

nodejs Browserify node-xmpp bundle error: cannot find module dns

I have created a JS bundle file from node-xmpp using Browserify but when I load my website I get the following error in the Google Chrome Javascript console:
Uncaught Error: Cannot find module 'dns'
I tried installing the browser-request node package using npm install -g browser-request and to rebuild the JS bundle but I still get the same error.
What do I need to include/install in order to get rid of this error?
Note: I am using a debian server with the latest version of nodejs and Browserify
I found an commit that has not been added to the latest build yet that solved my problem.
https://github.com/dodo/node-xmpp/commit/a49e7be0e43885060aaf26c2772b41c618624f12
I've added a screenshot containing the changes for if the link dies:

Resources