Azure Function dependencies - Invalid ELF header - node.js

I'm trying to run an Azure Function that has a dependency on TensorflowJS, resulting in an invalid ELF header. I know this is usually a sign that the dependency has been built for a different architecture. That makes sense in this case, locally I'm running OSX and deploying to Linux.
The deployment works fine via VSCode, it's only when I call the function from Postman that the error surfaces. How do I run the dependency installation on Azure rather than building locally and uploading a zip? This is what VSCode seems to be doing via the Azure plugin.
Function dependencies:
"dependencies": {
"#anzp/azure-function-multipart": "^3.1.0",
"#tensorflow/tfjs-node": "^4.2.0"
},
"devDependencies": {
"#azure/functions": "^3.0.0",
"#types/node": "16.x",
"azure-functions-core-tools": "^4.x",
"typescript": "^4.0.0"
}
Output Error:
Result: Failure Exception: Worker was unable to load function predict: '/home/site/wwwroot/node_modules/#tensorflow/tfjs-node/lib/napi-v8/tfjs_binding.node: invalid ELF header' Stack: Error: Worker was unable to load function predict: '/home/site/wwwroot/node_modules/#tensorflow/tfjs-node/lib/napi-v8/tfjs_binding.node: invalid ELF header' at Object.Module._extensions..node (node:internal/modules/cjs/loader:1239:18) at Module.load (node:internal/modules/cjs/loader:1033:32) at Function.Module._load (node:internal/modules/cjs/loader:868:12) at Module.require (node:internal/modules/cjs/loader:1057:19) at Object.apply (/azure-functions-host/workers/node/dist/src/worker-bundle.js:2:42034) at require (node:internal/modules/cjs/helpers:103:18) at Object.<anonymous> (/home/site/wwwroot/node_modules/#tensorflow/tfjs-node/dist/index.js:72:16) at Module._compile (node:internal/modules/cjs/loader:1155:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10) at Module.load (node:internal/modules/cjs/loader:1033:32)

I fixed this by using a GitHub workflow to deploy the function rather than doing it via VS Code. This way I was able to build for Linux and the error disappeared.

Related

NextJS build error - ReferenceError: navigator is not defined

I'm running into this special error message while trying to build a simple NextJS application (using npm run build):
> Build error occurred
ReferenceError: navigator is not defined
at /cdk-next/next-frontend/node_modules/codemirror/lib/codemirror.js:18:19
at /cdk-next/next-frontend/node_modules/codemirror/lib/codemirror.js:11:83
at Object.<anonymous> (/cdk-next/next-frontend/node_modules/codemirror/lib/codemirror.js:14:2)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/cdk-next/next-frontend/node_modules/easymde/src/js/easymde.js:2:18) {
type: 'ReferenceError'
}
info - Collecting page data .
I don't know who codemirror is, or why it's not letting me build my project. From reading around I gather that this issue occurs with NextJS when trying to build a project on the server side instead of the client side, because the project does not have access to a window or navigator. In that case, what should I do? The tutorial I'm following seems to breeze through this step just fine, so should I just look at their package.json and downgrade all of my packages? Any advice would be appreciated.
The error was with my import of import SimpleMDE from "react-simplemde-editor" (located in create-post.js of the repo link above).
I implemented the solution proposed by modikum here: https://github.com/dabit3/next.js-amplify-workshop/issues/21.
Now the project builds successfully.

Running Electron on windows: Error: A dynamic link library (DLL) initialization routine failed

I am trying to the run an electron app on windows that uses aws-crt. Everything works fine on MacOS.
But in windows, I get this error:
App threw an error during load
Error: A dynamic link library (DLL) initialization routine failed.
\\?\C:\Code\mir-kiosk-electron\electron-kiosk\node_modules\aws-crt\dist\bin\win32-x64\aws-crt-nodejs.node
at process.func [as dlopen] (electron/js2c/asar_bundle.js:5:1846)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1138:18)
at Object.func [as .node] (electron/js2c/asar_bundle.js:5:1846)
at Module.load (internal/modules/cjs/loader.js:935:32)
at Module._load (internal/modules/cjs/loader.js:776:14)
at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
at Module.require (internal/modules/cjs/loader.js:959:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\Code\mir-kiosk-electron\electron-kiosk\.webpack\main\index.js:8461:19)
at Object../node_modules/aws-crt/dist/native/binding.js (C:\Code\mir-kiosk-electron\electron-kiosk\.webpack\main\index.js:8470:30)
webpack built f8189be91ec9475472dc in 1864ms
What should I do?
I found a similar issue in https://github.com/electron/electron/issues/11853.
It says I need to rebuild the node module.
I have already done
.\node_modules\.bin\electron-rebuild.cmd
The error is still there.
Here is my package.json
"dependencies": {
"aws-crt": "^1.7.1",
"aws-iot-device-sdk-v2": "^1.5.1",
"axios": "^0.21.1",
"electron-squirrel-startup": "^1.0.0",
"jimp": "^0.16.1",
"pixelmatch": "^5.2.1",
"pngjs": "^6.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2"
}
My gut feeling is I need to rebuild aws-crt for electron. But how do I do it?

Issues with Sharp in Azure functions

Hi I have been trying to deploy my code for resizing image streams in azure function.
It seems to be working perfectly fine in local, even deployment via VS code is successful.
But when I try to trigger the function, I get below exception.
Relatively new to both nodejs and azure, any suggestions?
2021-06-08T04:51:24.370 [Information] Executing 'Functions.HttpTrigger1' (Reason='This function was programmatically called via the host APIs.', Id=7bd3aba0-8833-4ffe-b2c7-a061533fef6a)
2021-06-08T04:51:24.444 [Error] Executed 'Functions.HttpTrigger1' (Failed, Id=7bd3aba0-8833-4ffe-b2c7-a061533fef6a, Duration=17ms)
Result: Failure
Exception: Worker was unable to load function HttpTrigger1: 'Error: 'win32-x64' binaries cannot be used on the 'win32-ia32' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the 'win32-ia32' platform.'
Stack: Error: 'win32-x64' binaries cannot be used on the 'win32-ia32' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the 'win32-ia32' platform.
at Object.hasVendoredLibvips (C:\home\site\wwwroot\node_modules\sharp\lib\libvips.js:82:13)
at Object.<anonymous> (C:\home\site\wwwroot\node_modules\sharp\lib\constructor.js:7:22)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\home\site\wwwroot\node_modules\sharp\lib\index.js:3:15)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
According to the error message, we need to update Azure function as 64 bit Platform. Regarding how to do that, please refer to here.

Google Cloud Function not recognizing Papaparse 5.0 Dependency

I am building a Node.js Google Cloud function, and it is not recognizing the dependency "papaparse":
in package.json
"dependencies": {
"papaparse": "^5.0.0",
"twilio": "^3.33.2"
}
Error code I am getting:
Function failed on loading user code. Error message: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'papaparse'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/srv/index.js:8:14)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
I have tried reinstalling papaparse, running npm audit, but those steps haven't helped.
Does anyone know why this would happen?
I just managed to deploy a Cloud Function with papaparse.
For this you just need to deploy your function from the Cloud Shell. First create a folder where you gonna insert all your files. Then clone the repo from the papaparse github with the command git clone into that folder.
Now after adding your Index.json and your Package.json you can deploy your Cloud Function following this Deploying from Your Local Machine documentation.

Error running Gulpfile from Visual Studio 2015 task runner

I am building a gulpfile to use in my aps.net winforms project. So far I have the following in the package.json
{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"devDependencies": {
"browserify": "^13.1.0",
"del": "2.2.0",
"gulp": "^3.9.1",
"gulp-sourcemaps": "^2.2.0",
"gulp-typescript": "^3.0.2",
"tsify": "^2.0.2",
"vinyl-source-stream": "^1.1.0"
}
}
and the gulp file has
/// <binding BeforeBuild='default' />
/*
This file in the main entry point for defining Gulp tasks and using Gulp plugins.
Click here to learn more. http://go.microsoft.com/fwlink/?LinkId=518007
*/
var gulp = require('gulp');
var del = require('del');
var ts = require("gulp-typescript");
var tsProject = ts.createProject("tsconfig.json");
var sourcemaps = require('gulp-sourcemaps');
gulp.task('default', function () {
// place code for your default task here
});
My node version is 6.9.1
If I run this from the command line ('gulp') it works fine. But in the Visual Studio task runner, it fails to load, and in the out put I see the following error. This error starts after I add the line var sourcemaps = require('gulp-sourcemaps');
Failed to run "H:\dev\myproj\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
H:\dev\myproj\node_modules\gulp-sourcemaps\node_modules\strip-bom\index.js:2
module.exports = x => {
^
SyntaxError: Unexpected token >
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (H:\dev\myproj\node_modules\gulp-sourcemaps\src\init.js:10:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
Also adding var tsify = require("tsify"); I get another error...
Failed to run "H:\dev\myproject\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
TypeError: Object #<Object> has no method 'debuglog'
at Object.<anonymous> (H:\dev\myproject\node_modules\tsify\index.js:4:32)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (H:\dev\myproject\gulpfile.js:17:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
Anyone have any ideas why I am getting this?
Thanks in advance!
My problem was I didn't realize Visual Studio has it's own (way out of date) version of the node tools (installed within the Visual Studio folders somewhere). How untidy!
To make it use the "global" node tools, I could go to the menu Tools | Options | Projects and Solutions | External Web Tools and move the $(PATH) to be before the $(DevEnvDir)\* locations. After I did this, my Gulp file would load.
The other option may have been to update the Visual Studio node tools via the Tools | Extensions and Updates, but (I think) I'd prefer to use the same external tools I will use outside of Visual Studio.
After some investigate with me facing the same issue, it seems to be a problem with version compatibility between your nodejs install, and your package dependency "strip-bom".
An adhoc fix is to change from:
module.exports = x => {
to:
module.exports = function (x) {
You might want to check this out:
Gulp-Sourcemaps, SyntaxError: Unexpected token >
That seems to solve the issue for me, but not such a nice method.
The problem is that you might be running an old version of node. Try to use the command node -v or nodejs -v to check your version.
Though it might not be your case, but great for others to come by and see this, Debian/Ubuntu actually has an an outdated version of node on its package manager "apt-get". So it is highly possible that you're still running an old version such as 0.10.25.
The real fix I'd recommend (which I ended up doing), is to upgrade your node version. As of current date, version 6.9.1 seems to be the latest stable.
You can check the install guide at the nodejs official website here:
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

Resources