Cannot find module './collection/batch/unordered' - Node JS on Heroku - node.js

I have a problem that is driving me crazy for two days now. I have deployed a node app on heroku that worked well. Two days ago, I did an update of my modules (I am not 100% sure it is directly linked to my problem), and since I keep getting this message on my logs :
Error: Cannot find module './collection/batch/unordered'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/app/node_modules/mongodb/lib/mongodb/collection.js:21:17)
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)
Failed to load c++ bson extension, using pure JS version
Locally, the app works perfectly.
I tried to change versions back to what it was, without success.
So I checked in node_modules/mongodb/lib/mongodb, and indeed I did not find the "batch" folder and thus the unordered.js file, required by the node_modules/mongodb/lib/mongodb/collection.js file.
I tried to uninstall and re install mongodb. The batch folder and the unordered.js did appear. But the error still remains. And if I re deploy on Heroku, the batch folder is missing again.
I have strictly no idea what to try now, and I would deeply appreciate some help. Thank you !
EDIT :
Here is my packages.json :
{
"name": "Killerapp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"engines": {
"node": "0.10.26"
},
"dependencies": {
"express": "3.5.1",
"ejs" : "~0.8.5",
"mongodb": "1.4.2",
"mongoose": "3.8.8",
"connect-mongo": "*",
"passport" : "~0.1.17",
"connect-flash" : "~0.1.1",
"bcrypt-nodejs" : "latest",
"moment" : "latest"
}
}

Is there a reason you have hardcoded a version of mongodb in your dependencies? I believe mongoose will pull in the right version...
Try removing mongodb from your package.json, remove your node_modules from git, then push to heroku.

Related

Electron cannot open shared object file from node_modules folder

On electron, the node module vosk needs to access some shared objects located in node_modules/vosk/lib/.
The issue I am having right now is that, when I do require('vosk') in my main.js and try to execute my AppImage file, I get:
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Dynamic Linking Error: /tmp/.mount_CantooClaxGf/resources/app.asar/node_modules/vosk/lib/linux-x86_64/libvosk.so: Cannot open the shared object: It's not a folder
at new DynamicLibrary (/tmp/.mount_CantooClaxGf/resources/app.asar/node_modules/ffi-napi/lib/dynamic_library.js:75:11)
at Object.Library (/tmp/.mount_CantooClaxGf/resources/app.asar/node_modules/ffi-napi/lib/library.js:47:10)
at Object.<anonymous> (/tmp/.mount_CantooClaxGf/resources/app.asar/node_modules/vosk/index.js:24:21)
at Module._compile (internal/modules/cjs/loader.js:1145:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1166:10)
at Module.load (internal/modules/cjs/loader.js:981:32)
at Module._load (internal/modules/cjs/loader.js:881:14)
at Function.Module._load (electron/js2c/asar.js:769:28)
at Module.require (internal/modules/cjs/loader.js:1023:19)
at require (internal/modules/cjs/helpers.js:77:18)
I tried to add vosk to the files in the build:
"build": {
"files": [
"dist/**/*",
"src/assets/icons/*",
"electron.js",
"package.json",
"assets/models/*",
"node_modules/vosk/lib/*"
],
I can now see the files in the app.asar.unpacked/node_modules/vosk/lib/ folder, but when executing the app, I'm still having the same error.
I found this answer mentioning a hack, but it didn't solve my issue and I still have the exact same error.
How am I supposed to package the shared objects in a way that vosk will find them?
I could solve the issue with this config for electron, putting all the dependencies of vosk in the extraResources field:
"build": {
"extraResources": [
"node_modules/at-least-node/**/*",
"node_modules/builder-util-runtime/**/*",
"node_modules/debug/**/*",
"node_modules/ffi-napi/**/*",
"node_modules/fs-extra/**/*",
"node_modules/get-symbol-from-current-process-h/**/*",
"node_modules/get-uv-event-loop-napi-h/**/*",
"node_modules/graceful-fs/**/*",
"node_modules/jsonfile/**/*",
"node_modules/ms/**/*",
"node_modules/node-addon-api/**/*",
"node_modules/node-gyp-build/**/*",
"node_modules/ref-napi/**/*",
"node_modules/ref-struct-di/**/*",
"node_modules/sax/**/*",
"node_modules/universalify/**/*",
"assets/models/**/*"
],
"files": [
"dist/**/*",
"src/assets/icons/*",
"electron.js",
"package.json"
],
I also needed this lib.
It's now working as expected
I solved by updating my electron-builder configuration in package.json to be
{
"build": {
"asar": true,
"asarUnpack": [
"node_modules"
],
}
}
Then ensuring the unpacked path was used instead:
var dirPath = __dirname.includes('.asar') ? __dirname.replace('.asar', '.asar.unpacked') : __dirname;

How to install node-hid for electron

I'm trying to get a simple electron application running that interacts with an HID device.
I am running into a lot of difficulty, I am able to install and run node-hid, just not within electron.
My package.json looks like this:
{
"name": "test-proj",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "electron .",
"rebuild": "electron-rebuild --force",
"postinstall": "electron-rebuild"
},
"author": "me",
"license": "ISC",
"devDependencies": {
"electron": "^9.2.0",
"electron-rebuild": "^1.11.0"
},
"dependencies": {
"node-hid": "^1.3.0"
}
}
My main.js has the standard electron demo boilerplate code plus some HID calls:
const {app, BrowserWindow, ipcMain} = require('electron');
var HID = require('node-hid');
var device = new HID.HID(5824, 1500);
// Standard electron app window stuff
When trying to run the app I immediately get an error on new HID.HID():
Error: Module did not self-register: '\\?\C:\Users\Nathan\Desktop\carriage_return_app\node_modules\node-hid\build\Release\HID.node'.
at process.func [as dlopen] (electron/js2c/asar.js:140:31)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1034:18)
at Object.func [as .node] (electron/js2c/asar.js:140:31)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module._load (electron/js2c/asar.js:769:28)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at bindings (C:\Users\Nathan\Desktop\carriage_return_app\node_modules\bindings\bindings.js:112:48)
at loadBinding (C:\Users\Nathan\Desktop\carriage_return_app\node_modules\node-hid\nodehid.js:25:42)
Looking around I have seen a few examples of how to install node-hid and use it in electron, but none have helped me.
I have followed the electron-rebuild instructions here: https://www.electronjs.org/docs/tutorial/using-native-node-modules
I have also followed the instructions and copied the examples from here: https://github.com/node-hid/node-hid#electron-projects-using-node-hid
No luck. I get module did not self-register every time. node-hid is supposed to support electron and I don't see other people complaining.
Anyone come across this or have ideas to fix the issue?
The problem has been solved, so I will mark this as answered. I think I would still like more information on WHY though.
The hint came from building the two example projects:
https://github.com/todbot/electron-hid-toy
https://github.com/todbot/electron-hid-test
Running the first item, electron-hid-test worked off the bat. Adding electron-builder as a dependency and adding "postinstall": "electron-builder install-app-deps" as a script solved the issue in my project, I don't want electron-builder yet but at least it indicated that node-hid can work with electron given a specific setup.
The second item also worked, but not with:
npm install
npm rebuild
npm start
Instead it was specifically required to add the run command to the rebuild command:
npm install
npm run rebuild
npm start
After that, it works.
Any insights as to why this behaves differently?

ElectronJS build doesn't include needed folder

I'm working on a ElectronJS and ExpressJS project to build an application that runs an API in background and show a system tray with some features to control and monitor that API.
"electron": "^4.0.4",
"electron-builder": "^20.38.5",
I use electron-builder to generate an installer for macOS, and Windows (.exe with nsis and .dmg) packages containing my express API built app as it is.
That's mean, I build it separately and call it's entry point build/index.js in my electron's main.js, Despite, that hook and everything else is fine in development env. But when i run the build, it show me that error:
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Cannot find module 'express'
at Module._resolveFilename (internal/modules/cjs/loader.js:584:15)
at Function.Module._resolveFilename (/Users/username/WebstormProjects/my-api-monitor/release/mac/API monitor.app/Contents/Resources/electron.asar/common/reset-search-paths.js:43:12)
at Function.Module._load (internal/modules/cjs/loader.js:510:25)
at Module.require (internal/modules/cjs/loader.js:640:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/Users/username/WebstormProjects/my-api-monitor/release/mac/API monitor.app/Contents/Resources/app/api/build/index.js:19:16)
at Object.<anonymous> (/Users/username/WebstormProjects/my-api-monitor/release/mac/API monitor.app/Contents/Resources/app/api/build/index.js:208:3)
at Module._compile (internal/modules/cjs/loader.js:693:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:704:10)
at Module.load (internal/modules/cjs/loader.js:602:32)
I guess the problem is that the node_modules of my API in /build folder isn't packaged in the app, and i can't achieve that with the normal way documented in electron-builder readme.
For more details, here is my files tree.
Also, my electron-builder config. :
"asar": false,
"files": [
"main.js",
"api/**/*",
"resources/**/*"
],
"directories": {
"buildResources": "resources",
"output": "release"
}
Same issue with or without asar, i jsut keep it false to check if folders and files are included right.
Any idea will be helpful.

dialog flow v2 code not running

I was testing the new code according to v2. Link: Build Your First App with Dialogflow
code:
'use strict';
const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
const app = dialogflow({debug: true});
app.intent('Default Welcome Intent', conv => {
console.log("-----welcome intent-----");
conv.ask('Welcome');
});
exports.testMain = functions.https.onRequest(app);
But when I simulate it, it shows :
MalformedResponse
'final_response' must be set.
What can I do?
The request is not reaching the function though Fulfillment is enabled.
---------UPDATED------------
now I am getting this error when I try to deploy the function to firebase:
Function load error: Code in file index.js can't be loaded
Is there a syntax error in your code?
Detailed stack trace: TypeError: dialogflow is not a funct
at Object.<anonymous> (/user_code/index.js:6:13)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at getUserFunction (/var/tmp/worker/worker.js:388:24)
at loadUserCode (/var/tmp/worker/worker.js:444:18)
I am unable to understand???
Here is my package.json:
{
"name": "some name",
"description": "some desc",
"version": "0.0.1",
"author": "Google Inc.",
"engines": {
"node": "~4.2"
},
"dependencies": {
"actions-on-google": "^1.0.0",
"firebase-admin": "^5.11.0",
"firebase-functions": "^1.0.0",
"dialogflow": "^0.3.0",
"request": "^2.85.0",
"uuid": "^3.0.1"
}
}
------update 2------
I have changed node to :
"engines": {
"node": "~6.0"
still same problem
-----Update 3--------
Deployment complete, but when the request goes to it, it shows:
Confirm which version of the actions-on-google library you're using. Your dependencies of "actions-on-google": "^1.0.0" specifies version 1.x of the library, but the rest of your usage is via the 2.0.0 syntax. The error suggests that there is no dialogflow object, which is also provided in version 2 of the library, but not version 1.
To use version 2.0.0 and up, you need to change the line in your package.json to
"actions-on-google": "^2.0.0"
and then run
npm update
Check what version of node you're using. The package.json suggests that you're using node 4, when you need to be using at least node 6 if you're using =>.
Since Firebase Cloud Functions is node 6 as well, you should likely switch to it for your local development as well. (Node itself is at version 8 for LTS, and working on version 9, so you should certainly consider updating.)
Make sure that fulfillment is enable in the Dialogflow dashboard and that v2 of the API is turned on? Also check that the intent name you are using in your fulfillment matches the one in Dialogflow.
Your code looks good to me. Its probably a configuration issue.
Trying changing conv.ask('Welcome') to conv.close('Welcome');
also remove console.log("-----welcome intent-----"); line just for testing
changed the package.json:
"engines": {
"node": "~6.11.1"
},
"dependencies": {
"actions-on-google": "^2.0.0",
"firebase-admin": "^5.11.0",
"firebase-functions": "^1.0.0",
"dialogflow": "^0.3.0",
"request": "^2.85.0",
"uuid": "^3.0.1"
}
And this works

How to get semantic/gulp/webpack to work in electron-react-boilerplate

I am trying to port a react app to electron using electron-react-boilerplate but I'm using semantic-ui which suggested being set up with gulp. electron-react-boilerplate uses webpack to handle all of its packaging and I can't get webpack +gulp to work so everything will package in the electron app.
I'm trying this link that explains how to pipe webpack configs through gulp tasks but I'm getting an "unexpected token import" error from the webpack config.
.babelrc
{
"presets": ["es2015", "stage-0", "react"],
"plugins": ["add-module-exports"],
"env": {
"production": {
"presets": ["react-optimize"],
"plugins": ["babel-plugin-dev-expression"]
},
"development": {
"plugins": ["tcomb"],
"presets": ["react-hmre"]
},
"test": {
"plugins": [
["webpack-loaders", { "config": "webpack.config.test.js", "verbose": false }]
]
}
}
}
simple gulpfile.js straight from the link above:
var gulp = require('gulp');
var webpack = require('webpack-stream');
gulp.task('default', function() {
return gulp.src('src/entry.js')
.pipe(webpack())
.pipe(gulp.dest('dist/'));
});
the webpack dev file is here,
note some of the names are changed between this boilerplate version and my project but otherwise it's the same.
the error:
Configurator>gulp
[09:52:40] Using gulpfile C:\git\Configurator\gulpfile.js
[09:52:40] Starting 'default'...
[09:52:40] 'default' errored after 8.28 ms
[09:52:40] C:\git\Configurator\webpack.config.development.js:7
import webpack from 'webpack';
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:513:28)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Gulp.<anonymous> (C:\git\Configurator\gulpfile.js:7:18)
at module.exports (C:\git\Configurator\node_modules\orchestrator\lib\runTask.js:34:7)
the internet tells me that getting rid of the import errors should be as simple as using the 'es2015' preset in .babelrc but it's there and it's not helping.
I can get the dev server to work in the electron app with the semantic-ui stuff after the initial gulp build for semantic, but for some reason it doesn't build into the electron package when I try to package an installer to deploy this thing.
When I run the electron app dev server through webpack it works fine though, except I get two errors:
cannot set property exports of undefined
and
locals[0] does not appear to be a module object with hot module replacement API enabled
the latter stacktrace goes back to some semantic imports in one of my react files.
I'm totally at a loss as to how to make all this stuff work together.

Resources