Getting error when deploying a Google Cloud Function after Node upgrade - node.js

I updated Brew then updated Node from 10.12.0 -> 13.8.0
Now, I get the following error when trying to deploy a Google Cloud Function
firebase deploy --only functions:createJWT
i functions: preparing functions directory for
uploading...
Error: Error parsing triggers: Failed to load gRPC binary module
because it was not installed for the current system Expected
directory: node-v79-darwin-x64-unknown Found:
[node-v64-darwin-x64-unknown] This problem can often be fixed by
running "npm rebuild" on the current system Original error: Cannot
find module
'/Users/.../cloud-functions/functions/node_modules/grpc/src/node/extension_binary/node-v79-darwin-x64-unknown/grpc_node.node'
Require stack:
- /Users/.../cloud-functions/functions/node_modules/grpc/src/grpc_extension.js
- /Users/.../cloud-functions/functions/node_modules/grpc/src/client_interceptors.js
- /Users/.../cloud-functions/functions/node_modules/grpc/src/client.js
- /Users/.../cloud-functions/functions/node_modules/grpc/index.js
- /Users/.../cloud-functions/functions/node_modules/#google-cloud/common-grpc/src/service.js
- /Users/.../cloud-functions/functions/node_modules/#google-cloud/common-grpc/src/operation.js
- /Users/.../cloud-functions/functions/node_modules/#google-cloud/common-grpc/src/index.js
- /Users/.../cloud-functions/functions/node_modules/#google-cloud/logging/src/index.js
- /Users/.../cloud-functions/functions/index.js
- /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js
Try running "npm install" in your functions directory before
deploying.
Tried npm rebuild and npm install in my functions directory and nothing works
Furthermore...could this issue be due to the fact that GCF Node runtime enviroment is Node10 and I have installed Node13 on my machine? - according to these docs:
https://cloud.google.com/functions/docs/concepts/nodejs-10-runtime
I am struggling to revert back to Node10, have tried by running brew install node#10 and get this:
Then tried running the following command as per output above to symlink it to /usr/local but still no luck
echo 'export PATH="/usr/local/opt/node#10/bin:$PATH"' >> ~/.bash_profile

Searching around about this error, indeed, this seems that the problem is related to your system waiting for a version and founding another one - as per this part of the error.
Error: Error parsing triggers: Failed to load gRPC binary module because it was not installed for the current system Expected directory: node-v79-darwin-x64-unknown Found: [node-v64-darwin-x64-unknown]
There are some options that you can give it a try, besides trying the npm rebuild. Another option might be updating the package.json - as per this case solved here - that would return your npm version to an old one.
Besides that, on this question in the Community, there are a few solutions that helped other users, that I would recommend you to take a look at it: NodeJs Error - Failed to load gRPC binary module because it was not installed for the current system Expected directory?
Let me know if the information helped you!

Trying to deploy to an unsupported Google Function execution environment won't work. According to the google docs the current supported environments are Node8 and Node10(beta), re-installing Node10 worked for me.

Related

Can't create a react native empty project, app.json not found

I am currently trying to get started with react native.
I set up the development environment referring to the documentation, but can't even pass the first step and create an empty project.
I am on Windows 11, Node 16.15.1, and NPM 8.12.2
I keep getting the following error when trying to init react-ative project with expo init awesomeProject
Error downloading and extracting template package: Error: npm exited with non-zero code: 1
× Something went wrong while downloading and extracting the template.
Can't read JSON file: D:\crna\awesomeProject\app.json
└─ Cause: Error: ENOENT: no such file or directory, open 'D:\crna\awesomeProject\app.json'
Does anyone has a suggestion ?
Don't really know what is the problem but i found a soluion that might help other people in the same situation as me! like said here just run in CMD instead of GitBash
Use sudo if on linux. And maybe Admin on windows.

How I i solve Build Failed on Azure Devops Pipeline when building a node application

I have been studying azure devops in the past weeek and i have been trying to deoploy my first node app on azure but i keep running on an error of build failed. and the error is
Error Cannot find module './routes/hostelRoutes' so i have checked and confirmed that the module is available because everything runs on my local machine. Below is a pic where i get the error
According to the error message:
Error Cannot find module './routes/hostelRoutes'
The ‘node_modules’ folder could have some issues.
You could try to remove the directory ‘/node_modules/’ and re-install the folder.
Please refer to the following command line script about removing and re-installing.
cd Project_folder
rm -rf node_modules
npm install
You could check this ticket How do I resolve “Cannot find module” error using Node.js? for some information

Node package dependencies on IBM Cloud Foundry - require/module is not defined (Package not loading)

I am working on an application via the toolchain tool on IBM Cloud and editing the code via the Eclipse Orion IDE. As I am not accessing this through my local cli, my understanding is that in order to so call npm install {package}, I would just need to include the package in the package.json file under dependencies and require it in my app. However, when I load the application, I get the require is not defined indicating that the package has not been installed. Moreover, the require() is being used in the app.js file with the application being launched but not from files in my public directory.
After playing around further, it seems it might have to do with the way the directory tree is being traced as the error is only thrown in subdirectories. For example, require('express') works in app.js which is in the main directory ./ but fails when it is called in test.js in ./subdirectory/test.js. I feel like I'm missing something painfully simple like configuration of endpoint or something.
I've been searching around but I can't seem to find how to get the packages loaded, preferably without using the cli. Appreciate any pointers. Thanks!
Update: After playing around further, I am also getting module is not defined error when trying to require from another file in the same directory. For example module.exports = 'str' returns this error. While trying to require('./file') returns the require is not defined. It might have to do with how node is wrapping the functions?
Update 2: Tried "start": "npm install && node app.js" in package.json but no luck. Adding a build stage which calls npm install before deployment also does not work
Update 3: After adding npm install build stage, I am able to see that the dependencies have been successfully built via the logs. However, the require is not defined error still persists.
Update 4: Trying npm install from my CLI doesn't work as well even though all packages and dependencies are present
Update 5: Running cf restage or configuring cache via cacheDirectories does not work as well
Opened a related question regarding deployment here
Found out my confusion was caused due to me not realizing that require() cannot be used on the client side unless via tools such as Browserify.

Not able to run composer rest server

While starting composer rest server I am getting error :
Connection fails: Error: Failed to load connector module "composer-connector-hlfv1" for connection type "hlfv1". Cannot find module '/home/user/.nvm/versions/node/v8.9.3/lib/node_modules/composer-rest-server/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64/grpc_node.node
there is no grpc_node.node file present in the above folder. I tried reinstalling compoer rest server but no luck.
There are lots of reasons for this. the grpc module is a binary module and usually npm will download a prebuilt binary for your platform. If however it cannot do that (eg server down, or the platform is not recognised) then it will attempt to build the binary from source.
You need to look at the output during the npm -g install of composer-rest-server to see what is reported when npm attempts to install grpc to determine what the problem is.
The following advice from another thread has worked for me. Please try:
Rebuild it
Go to the folder cd '/root/.nvm/versi ons/node/v8.9.1/lib/node_modules/composer-rest-server/'
(into the folder where you have 'composer-rest-server')
then run npm rebuild --unsafe-prem
It will work now
source - Error while generating REST api using hyperledger composer-rest-server in centOS

Azure and node js __dirname

Probably it is not specifically related to webpack/memory-fs, but I am getting the RangeError: Maximum call stack size exceeded error (see below for a call stack).
I have found out, that __dirname on Azure (webapp) returns \\100.78.172.13\volume-7-default\8f5ecde749dace2bb57a\4e07195f015b45ce8e9ba255dc901988\site\repository\Source\Website\Content\app\node_modules\webpack\node_modules\memory-fs\lib\normalize.js in my situation, while process.cwd() returns D:\home\site\repository\Source\Website\Content\app.
Is anything can be done from my side to configure node js to return D:\... instead of \\.. ?
Gist
How to reproduce:
Clone the https://github.com/intellismiths/webapp1 repository.
Create new Azure Web App (default settings).
Configure deployment source to use GitHub.
Click Sync. It will take 10+ minutes to complete and it will show that the deployment was successful.
Go to Application settings in Azure and change WEBSITE_NODE_DEFAULT_VERSION to 6.2.2
Go to kudu page and open powershell console.
Execute npm cache clean
Check node version by executing node -v. It should be v6.2.2
On Azure, navigate to D:\home\site\respository\src\WebApp1
Execute npm run build
In console, you should see a lot of errors which indicates that modules can not be resolved.
OPTIONAL. Test npm run build on your local machine - it should produce wwwroot/app.js without errors.
Update webpack.config.js to include context: __dirname to fix previous errors.
Execute npm run build
In console, you should see the "RangeError: Maximum call stack size exceeded" error.
Update 1
I only tried to set 6.2.2 runtime after adding the second package.json, so the project structure is not the simplest possible. Maybe just setting node to 6.2.2 breaks the build.
I could reproduce your issue following your steps. I found the key point was setting the WEBSITE_NODE_DEFAULT_VERSION to 6.2.2. And I found the webpack task worked fine if the WEBSITE_NODE_DEFAULT_VERSION was under 6.
Please downgrade the setting WEBSITE_NODE_DEFAULT_VERSION to the version under 6 e.g. 5.9.0 if your node.js modules do not need such high version.
And according the package.json of angular2 athttps://github.com/angular/angular/blob/master/package.json, it seems that the angular2 repository requires the node.js version between 5.4 and 6.
Additionally, the web application's root directory on Azure Web Apps is D:\home\site\wwwroot. So if you want to build your frontend project on Azure Web Apps, you need to locate to D:\home\site\wwwroot\wwwroot\mobile-web-app then run npm run build.
It's been fixed in master and it's proposed to be included in v6.4.0.
See: https://github.com/nodejs/node/issues/7175#issuecomment-239824532 and https://github.com/nodejs/node/pull/8070
After a long day of research, trial-and-error and various experimentation, I've found an acceptable workaround if you're not willing to downgrade to Node 5.*:
Downgrade to Node 6.1.0
Make sure to install webpack globally (with npm install -g webpack).
Just using 6.1.0 gets around the "maximum call stack size exceeded" error, but instead gave me a lot of resolve failures when running webpack from node_modules (using ./node_modules/.bin/webpack). Installing webpack globally finally got me past that.
If I understand it correctly, this whole issue with __dirname in Node >= 6.2 resolving to the UNC folder path instead of the mounted path is going to be fixed, there's an active discussion here.
I had the same issue.
Fixed it with UPGRADING npm not DOWNGRADING.
Bug is fixed in the npm versions newer than 6.5.
https://github.com/aumanjoa/chronas-community/blob/master/package.json#L48
I believe that your __dirname shows your persistant drive where the data is stored, while .cwd gives current directory from where node ran. This is because Azure runs from the Drive but files are stored at the persistent drive.
In your Gruntfile.js add
module.exports = function (grunt) {
grunt.file.setBase(__dirname);
// Code omitted
}
Refer: link

Resources