NodeJS-Electron-msnodesqlv8 - Error while loading binaries in msnodesqlv8 - node.js

Context: I am building an electron app, which is querying a sql server (remote server) to get the data from table. I am using mssqlnodev8.
Error: When I start the electron app using npm start, I get the below error -
Uncaught Error: None of the binaries loaded successfully. Is your node
version either latest 4, 5, 6, 7, 8 or 9 ?
at failIfNoBinaryExported (C:\Users\t9sau2\Documents\NodeJs\Renewalverification\node_modules\msnodesqlv8\lib\bootstrap.js:63)
at Object.liveLoad (C:\Users\t9sau2\Documents\NodeJs\Renewalverification\node_modules\msnodesqlv8\lib\bootstrap.js:50)
at Object. (C:\Users\t9sau2\Documents\NodeJs\Renewalverification\node_modules\msnodesqlv8\lib\bootstrap.js:79)
at Object. (C:\Users\t9sau2\Documents\NodeJs\Renewalverification\node_modules\msnodesqlv8\lib\bootstrap.js:81)
at Module._compile (internal/modules/cjs/loader.js:711)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:722)
at Module.load (internal/modules/cjs/loader.js:620)
at tryModuleLoad (internal/modules/cjs/loader.js:559)
at Function.Module._load (internal/modules/cjs/loader.js:551)
at Module.require (internal/modules/cjs/loader.js:658)
Additional information about electron app -
I am using bootstrap for my UI. As per electron faq site, I have the below code in my entry html file
<script>
window.nodeRequire = require;
delete window.require;
delete window.exports;
delete window.module;
</script>
All the modules except electron (index.js - entry point) is imported with
nodeRequire
Analysis done till now -
The javascript logic to connect to database and fetch records are in
separate js file. When I execute the file with 'node file.js', it
works perfectly fine and returns records.
The node version is v9.8.0. Electron version is 3.0.2
I analyzed bootstrap.js file in node_modules\msnodesqlv8\lib\bootstrap.js, line number 63. It traced to below code
var files = require('fs').readdirSync(binaryDir)
I changed that too nodeRequire, but it didnt work.
I have checked similar issues in github but none of the resolutions helped.
UPDATED
I analyzed the bootstrap.js in msnodesqlv8. These are the different error messages
Error while exporting binary Error:
\?\C:\Users\t9sau2\Documents\NodeJs\Renewalverification\node_modules\msnodesqlv8\lib\bin\sqlserverv8.electron.v2.0.4.ia32.node
is not a valid Win32 application.
\?\C:\Users\t9sau2\Documents\NodeJs\Renewalverification\node_modules\msnodesqlv8\lib\bin\sqlserverv8.electron.v2.0.4.ia32.node
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:166:20)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:740)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:166:20)
at Module.load (internal/modules/cjs/loader.js:620)
at tryModuleLoad (internal/modules/cjs/loader.js:559)
at Function.Module._load (internal/modules/cjs/loader.js:551)
at Module.require (internal/modules/cjs/loader.js:658)
at require (internal/modules/cjs/helpers.js:20)
at attemptToExportBinary (C:\Users\t9sau2\Documents\NodeJs\Renewalverification\node_modules\msnodesqlv8\lib\bootstrap.js:58)
at C:\Users\t9sau2\Documents\NodeJs\Renewalverification\node_modules\msnodesqlv8\lib\bootstrap.js:48
Error while exporting binary Error: The module
'\?\C:\Users\t9sau2\Documents\NodeJs\Renewalverification\node_modules\msnodesqlv8\lib\bin\sqlserverv8.electron.v2.0.4.x64.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 57. This version of Node.js requires
NODE_MODULE_VERSION 64. Please try re-compiling or re-installing the
module (for instance, using npm rebuild or npm install).
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:166:20)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:740)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:166:20)
at Module.load (internal/modules/cjs/loader.js:620)
at tryModuleLoad (internal/modules/cjs/loader.js:559)
at Function.Module._load (internal/modules/cjs/loader.js:551)
at Module.require (internal/modules/cjs/loader.js:658)
at require (internal/modules/cjs/helpers.js:20)
at attemptToExportBinary (C:\Users\t9sau2\Documents\NodeJs\Renewalverification\node_modules\msnodesqlv8\lib\bootstrap.js:58)
at C:\Users\t9sau2\Documents\NodeJs\Renewalverification\node_modules\msnodesqlv8\lib\bootstrap.js:48
Error while exporting binary Error:
\?\C:\Users\t9sau2\Documents\NodeJs\Renewalverification\node_modules\msnodesqlv8\lib\bin\sqlserverv8.node.v10.8.0.ia32.node
is not a valid Win32 application.
\?\C:\Users\t9sau2\Documents\NodeJs\Renewalverification\node_modules\msnodesqlv8\lib\bin\sqlserverv8.node.v10.8.0.ia32.node
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:166:20)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:740)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:166:20)
at Module.load (internal/modules/cjs/loader.js:620)
at tryModuleLoad (internal/modules/cjs/loader.js:559)
at Function.Module._load (internal/modules/cjs/loader.js:551)
at Module.require (internal/modules/cjs/loader.js:658)
at require (internal/modules/cjs/helpers.js:20)
at attemptToExportBinary (C:\Users\t9sau2\Documents\NodeJs\Renewalverification\node_modules\msnodesqlv8\lib\bootstrap.js:58)
at C:\Users\t9sau2\Documents\NodeJs\Renewalverification\node_modules\msnodesqlv8\lib\bootstrap.js:48

I had raised this issue in github report of msnodesqlv8. The owner updated the version, which resolved the issue. github link - https://github.com/TimelordUK/node-sqlserver-v8/issues/80

Related

Electron UI load native C++ addon on Windows error

I've createed simple native add-on using generator-napi-module. The module is successfully built.
Also, I've added folowing line in window.js:
const testmodule = require('testmodule')
When I start app with npm start, I've got following error:
ELECTRON_ASAR.js:166 Uncaught Error: A dynamic link library (DLL) initialization routine failed.
\\?\C:\Electron\simple-samples-master\activity-monitor\node_modules\testmodule\build\Release\testmodule-native.node
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:166:20)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:740)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:166:20)
at Module.load (internal/modules/cjs/loader.js:620)
at tryModuleLoad (internal/modules/cjs/loader.js:559)
at Function.Module._load (internal/modules/cjs/loader.js:551)
at Module.require (internal/modules/cjs/loader.js:658)
at require (internal/modules/cjs/helpers.js:20)
at Object.<anonymous> (C:\Electron\simple-samples-master\activity-monitor\node_modules\testmodule\lib\binding.js:1)
at Object.<anonymous> (C:\Electron\simple-samples-master\activity-monitor\node_modules\testmodule\lib\binding.js:6)
The module is working properly when I execute command:
node index
or test with:
npm test
What could go wrong here? Could this be related to security?
Also note that I tried to play with ffi-napi to load native library but the same error message appears.

Unable to start node.js application written with graphql

I have an application written in node.js with graphql, it is running on ubuntu sever, however, i cloned the code onto my local windows 10, installed all packages, and node environment, but when I try to start the app with "node index.js" I got the following error.
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be one of type string or Buffer. Received type object
at validChunk (_stream_writable.js:263:10)
at WriteStream.Writable.write (_stream_writable.js:297:21)
at Object.<anonymous> (D:/MyProjects/appletree/apple-tree-backend/configs/constants.js:5:17)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at loader (D:\MyProjects\appletree\apple-tree-backend\node_modules\babel- register\lib\node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (D:\MyProjects\appletree\apple- tree-backend\node_modules\babel-register\lib\node.js:154:7)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:690:17)
Emitted 'error' event at:
at errorOrDestroy (internal/streams/destroy.js:107:12)
at validChunk (_stream_writable.js:266:5)
at WriteStream.Writable.write (_stream_writable.js:297:21)
[... lines matching original stack trace ...]
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
Thanks for answering, I figured out the issue later as I looked into the code, the project used dotenv package which requires a .env file and this file is not included in the source code that's why I couldn't start the code on my local. I got the .env file from the production server and now the code can run on my local , thanks everyone.

ERR_PACKAGE_PATH_NOT_EXPORTED : Package subpath './dist/pako.es5.js' is not defined by "exports"

I have an issue with the deployment of a node app to production.
When I try to execute with Node a script I get the following error:
internal/modules/cjs/loader.js:498
throw new ERR_PACKAGE_PATH_NOT_EXPORTED(basePath, mappingKey);
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/pako.es5.js' is not defined by "exports" in /opt/iul/sat_web_lfr/node_modules/pizzip/node_modules/pako/package.json
at applyExports (internal/modules/cjs/loader.js:498:9)
at resolveExports (internal/modules/cjs/loader.js:514:23)
at Function.Module._findPath (internal/modules/cjs/loader.js:642:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1017:27)
at Function.Module._load (internal/modules/cjs/loader.js:899:27)
at Module.require (internal/modules/cjs/loader.js:1090:19)
at require (internal/modules/cjs/helpers.js:75:18)
at Object.<anonymous> (/opt/iul/sat_web_lfr/node_modules/pizzip/js/flate.js:5:12)
at Module._compile (internal/modules/cjs/loader.js:1201:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
at Module.load (internal/modules/cjs/loader.js:1050:32)
at Function.Module._load (internal/modules/cjs/loader.js:938:14)
at Module.require (internal/modules/cjs/loader.js:1090:19)
at require (internal/modules/cjs/helpers.js:75:18)
at Object.<anonymous> (/opt/iul/sat_web_lfr/node_modules/pizzip/js/compressions.js:14:19)
at Module._compile (internal/modules/cjs/loader.js:1201:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
at Module.load (internal/modules/cjs/loader.js:1050:32)
at Function.Module._load (internal/modules/cjs/loader.js:938:14)
at Module.require (internal/modules/cjs/loader.js:1090:19)
at require (internal/modules/cjs/helpers.js:75:18)
at Object.<anonymous> (/opt/iul/sat_web_lfr/node_modules/pizzip/js/utils.js:7:20) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
However when I execute this script on the testing server works fine.
We even copy and paste the node modules folder from the testing server to the production server but the error is the same.
I think is an error in some external package but I don't understand how the same configuration can have this kind of error depending on the system.
I've tried to update npm from 6.14.5 to 7.23.0 but the error persists.
Both testing and production server uses the same version of Node, 14.X
The only possibility remaining is that I'm using a different NODE_ENV variable between the 2 servers but looking at the error message it's seems unlikely.
Thanks in advance.

Electron: TypeError: Cannot create property 'default' on symbol 'Symbol(nodejs.util.inspect.custom)'

I've developed an electron app with following tech stack:
NodeJS (10.15) with Babel to allow ES6 import/export syntax.
Sequelize on SQLite and GraphQL to handle an internal database.
ReactJS (bundled) for views.
I've configured everything to work with Electron and running "electron" command in project root folder works without errors.
Now i'm trying to distribute it using this tutorial: https://electronjs.org/docs/tutorial/application-distribution
So i've simply downloaded the 4.1.4 binaries for windows and moved the project folder under resources/app/
But running the electron.exe i've the following error:
App threw an error during load
TypeError: Cannot create property 'default' on symbol 'Symbol(nodejs.util.inspect.custom)'
at Object.<anonymous> (C:\workspace\myapp\resources\app\node_modules\graphql\jsutils\nodejsCustomInspectSymbol.js:18:84)
at Object.<anonymous> (C:\workspace\myapp\resources\app\node_modules\graphql\jsutils\nodejsCustomInspectSymbol.js:20:3)
at Module._compile (internal/modules/cjs/loader.js:711:30)
at Module._compile (C:\workspace\myapp\resources\app\node_modules\pirates\lib\index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:722:10)
at Object.newLoader [as .js] (C:\workspace\myapp\resources\app\node_modules\pirates\lib\index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:559:12)
at Function.Module._load (internal/modules/cjs/loader.js:551:3)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (C:\workspace\myapp\resources\app\node_modules\graphql\jsutils\defineToJSON.js:8:57)
at Object.<anonymous> (C:\workspace\myapp\resources\app\node_modules\graphql\jsutils\defineToJSON.js:36:3)
at Module._compile (internal/modules/cjs/loader.js:711:30)
at Module._compile (C:\workspace\myapp\resources\app\node_modules\pirates\lib\index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:722:10)
at Object.newLoader [as .js] (C:\workspace\myapp\resources\app\node_modules\pirates\lib\index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:559:12)
at Function.Module._load (internal/modules/cjs/loader.js:551:3)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:20:18)
i've also tried to run npx electron resources/app/ from binaries folder and i've got the same error.
So i think the issue is something about the paths.
i've also tried electron-packager and the error is the same because this tool does the same process of guide above.
What can i do to fix it?
UPDATE1: after some investigations i've found that babel causes the issues. I guess when you run a project from a parent folder. I'm trying to find a solution
i've solved using this kind of configuration for babel/register:
const rootPath=path.resolve(path.join(__dirname, "../../"));
require("#babel/register")({
root: rootPath,
extends: path.join(rootPath, '.babelrc'),
ignore: [/node_modules/],
only: [rootPath],
})

Reuse usb package installed with npm in electron app

I have an atypical internet connection, sometimes I have it, but sometimes I do not and I need to save its use.
I need to use the usb library for node, I already have it installed in another node_modules (same operating system / same pc), but when I copy it from one node_modules to another it gives the error:
Error: Error en una rutina de inicialización de biblioteca de vínculos dinámicos (DLL).
\\?\D:\WindowsDev\CopyWatcher\node_modules\usb\src\binding\usb_bindings.node
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:166:20)
at Object.Module._extensions..node (module.js:671:18)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:166:20)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Module.require (module.js:586:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (D:\WindowsDev\CopyWatcher\node_modules\usb\usb.js:5:38)
at Object.<anonymous> (D:\WindowsDev\CopyWatcher\node_modules\usb\usb.js:417:3)
Is it possible to do something like this?
Thanks in advance

Resources