Error: Module version mismatch. when trying to launch in electron shell - node.js

When I try to launch my app in electron shell I get the below error:
I'm using node v0.12.3
I have installed electron-prebuilt
Uncaught Exception:
Error: Module version mismatch. Expected 43, got 14.
at Error (native)
at Object.module.(anonymous function) (ATOM_SHELL_ASAR.js:118:20)
at Object.module.(anonymous function) [as .node] (ATOM_SHELL_ASAR.js:118:20)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:298:12)
at Module.require (module.js:353:17)
at require (module.js:372:17)
at bindings (/src/git/superqa/node_modules/bcrypt/node_modules/bindings/bindings.js:76:44)
at Object.<anonymous> (/src/git/superqa/node_modules/bcrypt/bcrypt.js:3:35)
at Module._compile (module.js:418:26)
// my main.js file looks like this superqa/main.js
var app = require("./app/app.js");
var App = require("./src/app.js");
new App(app);
//my src/app.js looks like this superqa/src/app.js
var path = require("path");
var BrowserWindow = require('browser-window');
module.exports = App;
function App(app) {
var self = this;
this._app = app;
this._assetDir = path.resolve(__dirname, "..", "dist");
this.mainWindow = null;
app.on('ready', function() {
self.mainWindow = new BrowserWindow({
width: 1024,
height: 768
});
self.mainWindow.loadUrl("http://localhost:3000/login");
});
}

The problem is that the pre-built binaries were built with io.js 1.x, which uses a different (higher) ABI version than node.js. So if you want to use the pre-built version, you have to use io.js 1.x. Otherwise you will have to build electron yourself if you want to keep using node 0.12.x.

Related

Angular universal build breaks with the following error: throw Error("not supported");

Running the following command : npm run build:ssr && npm run serve:ssr runs 3 different compilation stages but on the last one it returns the following error resulting to the server not starting.
Error: not supported
at Root.loadSync (/var/www/html/stage/node_modules/#grpc/proto-loader/node_modules/protobufjs/src/root.js:234:15)
at Object.loadSync (/var/www/html/stage/node_modules/#grpc/proto-loader/node_modules/protobufjs/src/index-light.js:69:17)
at Object.<anonymous> (/var/www/html/stage/node_modules/#grpc/proto-loader/build/src/index.js:244:37)
at Module._compile (internal/modules/cjs/loader.js:721:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Module.require (internal/modules/cjs/loader.js:657:17)
at require (internal/modules/cjs/helpers.js:22:18)
Environment and packages"
Angular CLI: 8.3.3
Node: 11.6.0
OS: linux x64
Angular: 8.2.5
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, platform-webworker
... platform-webworker-dynamic, router, service-worker
My server.ts looks as follows
const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), 'dist');
const domino = require('domino');
const fs = require('fs');
const path = require('path');
const template = fs.readFileSync(path.join(__dirname, join(DIST_FOLDER, 'browser/index.html'))).toString();
const win = domino.createWindow(template);
global['window'] = win;
global['navigator'] = win.navigator;
global['Node'] = win.Node;
global['Event'] = win.Event;
global['Event']['prototype'] = win.Event.prototype;
global['document'] = win.document;
global["branch"] = null;
global['localStorage'] = localStorage;
Finally solved the problem.
1. Deleted problematic folder ./node_modules/#grpc/...
2. Manually uploaded a new #grpc folder with
#grpc
-- proto-loader
---- build/src/index.js
---- LICENCE
---- package.json
here's the repo to those who may find it useful
--> https://github.com/Gerald34/Angular-Universal-grpc
you can fix by adding process to your fake window in the server.ts file
win.process = process;
You can find more info in this article, with also other errors I encountered with Angular SSR + Firebase

Node.js - Import Package Issue - Not a Function

Using node v12.9.0 on macOS Mojave, have the following project structure (with app being the root folder):
app
\
utils.js
app.js
utils.js
console.log('utils.js')
const add = function(a ,b) {
return a + b
}
module.exports = add
app.js
const add = require('./utils.js')
const sum = add(4, -2)
console.log(sum)
Tried running this:
node app.js
Error:
app/app.js:3
const sum = add(4, -2)
^
TypeError: add is not a function
at Object.<anonymous> (/Users/devuser/app/app.js:3:13)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:999:10)
at internal/main/run_main_module.js:17:11
Can you try this:
utils.js
const add = function(a ,b) {
return a + b
}
module.exports = {
add : add
}
app.js
const utils = require('./utils.js')
const sum = utils.add(4, -2)
console.log(sum)
It actually works now using my original code inside both the Integrated Terminal that Visual Studio Code provides and the native macOS Terminal.
Now it just prints:
2
Don't know why it was had a TypeError earlier?
Am new to node.js so I can't comment on what changed?

Deployment of Node native modules to Azure WebSites,I'm experiencing some problems

I deploy a node application to the Azure website.
The tricky part is that I'm using a node module called "opencv" that needs to be compiled at install time using node-gyp.
I use the node-gyp rebuild --arch=ia32 command to compile it int the windows10. But when I used it in the Azure website, I get following problem:
Wed Apr 26 2017 04:48:35 GMT+0000 (Coordinated Universal Time): Application has thrown an uncaught exception and is terminated:
Error: The specified module could not be found.
\\?\D:\home\site\wwwroot\app\api\lib\opencv.node
at Error (native)
at Object.Module._extensions..node (module.js:434:18)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (D:\home\site\wwwroot\app\api\lib\image_operation.js:5:14)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
This is the code I call:
'use strict';
var fs = require('fs');
var path = require('path');
var opencv = require("./opencv.node");
function isContains(str, substr) {
return new RegExp(substr).test(str);
}
module.exports = {
post: function (imageInfo, data) {
if (isContains(imageInfo.imageName, ".yuv")) {
var imageName = imageInfo.imageName.substr(0, imageInfo.imageName.length - 3) + "jpg";
opencv.yuvToJpeg(path.resolve(__dirname, "../../image/" + imageName), imageInfo.width, imageInfo.height, Array.prototype.slice.call(data, 0));
} else if (isContains(imageInfo.imageName, ".jpg")) {
fs.writeFileSync(path.resolve(__dirname, "../../image/" + imageInfo.imageName), data);
}
return "success";
}
};
But that file is in-fact deployed on the server:
Please help me, and tell me what to do
Its readme says that "You'll need OpenCV 2.3.1 or newer installed before installing node-opencv". And as Azure Web Apps is a Software as a service (SaaS), we don't have the privilege to install arbitrary software there. But if that is a requirement for you, you'll need to use an alternative offering, like Cloud Service or VM.

Gulp-Sourcemaps, SyntaxError: Unexpected token >

Gulp / npm noobie here.
I'm trying to use gulp-sourcemaps, and for some reason, it crashes on var sourcemaps = require('sourcemaps').(It crash only when this line's in the file)
gulpfile:
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('generateApp', function () {
return gulp.src([some paths...])
.pipe(sourcemaps.init())
.pipe(concat('app.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest(path...));
});
Error :
C:\Projets\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> (C:\Projets\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)
Has anyone encounter this type of error?
I tried to google it, without any success.
I just started getting the same error and fixed it by replacing the code in C:\Projects\node_modules\strip-bom\index.js with this:
'use strict';
module.exports = function (x) {
if (typeof x !== 'string') {
throw new TypeError('Expected a string, got ' + typeof x);
}
// Catches EFBBBF (UTF-8 BOM) because the buffer-to-string
// conversion translates it to FEFF (UTF-16 BOM)
if (x.charCodeAt(0) === 0xFEFF) {
return x.slice(1);
}
return x;
};
Then, I had to run npm rebuild node-sass to get it to work again. It seems to be an issue with an older version of the Strip-bom node module.
For more info, check this out: https://github.com/sindresorhus/strip-bom/commit/e2a3c3b83706ee5baac284f3862d3f6b9e1564e5
UPDATED ANSWER:
This error is caused by using an older version of Node. The Strip-bom module is now using ES2015 (ES6) syntax which requires Node 5.0+. (See Node's ES2015 support list here)
To test your version of Node, run:
node -v
If it's less than 5.0, you'll need to update it. You can download the newest version of Node here:
https://nodejs.org/en/
After installing the new version of Node, I still needed to run npm rebuild node-sass to get Gulp up and running again.
The former answer will still work if you don't want to update your Node version, however, as Louis pointed out, manually editing node module files is not a best-practice.

Koa-pg Can't find module pg

Hey so I'm trying to get Nodejs Koa to talk to postgres using the Koa-pg module, but I keep getting a 'Can't find module pg' error.
I've tried to follow the koa-pg examples, but have come up short...so any advice would on how to progress would be appreciated.
If created my app.js file as follows:
var koa = require('koa');
var route = require('koa-route');
var koaPg = require('koa-pg');
var roads = require('./controllers/roads');
var app = module.exports = koa();
app.use(route.get('/roads/bbox/', roads.bbox));
app.listen(3000);
console.log('listening on port 3000');
And then created my controller file as follows:
var credentials = require('../credentials.js');
var environment = credentials.dev;
app.use(koaPg('postgres://' + environment.user + '#' + environment.host + ':' + environment.port + '/' + environment.database))
module.exports.bbox = function * bbox(next) {
var result = yield this.koaPg.db.client.queryPromise('SELECT now()')
console.log('result: ', result)
this.body = result.rows[0].now.toISOString()
};
But I'm getting the following error:
module.js:338
throw err;
^
Error: Cannot find module 'pg'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (c:\Users\User\Documents\restful_koa\node_modul
es\koa-pg\index.js:12:27)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
This is only a personal project but I'd love to understand where i'm going wrong.
Cheers
As mentioned in the comments:
You need to install the pg module via npm install pg or npm install pg --save if you want to save it to package.json.
The reason you need to do this is koa-pg has co-pg as a dependency so when you install the former the latter is also installed. But pg is not a dependency of co-pg and that is why you have to install it separately.

Resources