Primordials is not defined - node.js

I'm trying to execute this code but I don't know why it shows error. I'm new at Nodejs, so i attach the code and ss of error please help how to fix this
var webshot = require('webshot');
var flatiron = require('flatiron');
var app = flatiron.app;
app.use(flatiron.plugins.http);
app.router.get('/getImage', function() {
var self = this;
var requestUrl = this.req.headers['head'];
console.log(requestUrl);
webshot(requestUrl, function(err, renderStream) {
renderStream.pipe(self.res);
});
});
app.start(3000,"IP Address");
console.log('Starting Node Server');
error =
Debugger attached.
Waiting for the debugger to disconnect...
fs.js:45
} = primordials;
^
ReferenceError: primordials is not defined
at fs.js:45:5
at req_ (c:\Users\HOME\Desktop\NodeScripts\node_modules\natives\index.js:143:24)
at Object.req [as require] (c:\Users\HOME\Desktop\NodeScripts\node_modules\natives\index.js:55:10)
at Object.<anonymous> (c:\Users\HOME\Desktop\NodeScripts\node_modules\graceful-fs\fs.js:1:37)
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)
Process exited with code 1

First note encountering this kind of issue is not common when using Node.js. The packages webshot and flatiron haven't been maintained for 5 years at the time of writing, which is the primary reason they're incompatible with the current version of Node.js.
Typically when this error is encountered, you either need to use different packages, or downgrade to an older version of Node.js. According to the comments here, you should be able to downgrade to Node.js v11, but I highly suggest exploring more recently maintained packages like capture-website and express in order to stick with the latest LTS version of Node.js.

Related

error while connecting sqlite database file using node js

I am new to Node.Js and have written the below code to connect to the SQLite db file. But unfortunately getting error-ed out. please help
Node - 4.6.0:
const sqlite3 = require('sqlite3').verbose();
let db =new sqlite3.Database('./db/program', sqlite3.OPEN_READWRITE,(err)
if (err) { console.error(err.message); }
console.log('Connected to the database.');});
Error message:
let db = new sqlite3.Database('./db/program', sqlite3.OPEN_READWRITE, (err) => {
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:974:3
As you're using Node 4.6.0 it doesn't support ES6 syntax out of the box. You need to use the strict mode and write code.let is supported out of the box after Node v6.0.0.
So, maybe you can upgrade Node.JS or you can just add,
"use strict";
in the 1st line of the code. It should work.
Check ES6 compatibility here: https://node.green/#ES2015-bindings-let
Learn more about Strict mode: https://www.w3schools.com/js/js_strict.asp

Adding gulp-sass breaks by task runner

I have a basic gulp setup in VS2017 to minify my Javascript. I decided to add gulp-sass (my package.json says I'm on gulp-sass v4.0.1) but it throws this error:
C:\Work\MyProject\MyProject\node_modules\gulp-sass\index.js:66
let sassMap;
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:404:10)
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> (C:\Work\MyProject\MyProject\gulpfile.js:11:12)
at Module._compile (module.js:397:26)
at Object.Module._extensions..js (module.js:404:10)
My gulpfile looks like this:
var gulp = require('gulp');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var watch = require('gulp-watch');
var uglify = require('gulp-uglify');
var sass = require('gulp-sass');
gulp.task('minify', function () {
gulp.src('src/**/*.js')
.pipe(uglify({ mangle: false }))
.pipe(concat('scripts.min.js'))
.pipe(gulp.dest('Content'));
});
gulp.task('sass', function () {
gulp.src('src/css/**/*.scss')
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(gulp.dest('Content'));
});
gulp.task('watch', function () {
gulp.watch('src/**/*.js', ['minify']);
});
I did some Googling and a simple fix suggested was to add "use strict" to the top of the offending file, in this case index.js:66. However, after doing that I get:
Failed to run "C:\Work\MyProject\MyProject\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
C:\Work\MyProject\MyProject\node_modules\node-sass\lib\binding.js:15
throw new Error(errors.missingBinary());
^
Error: Missing binding C:\Work\MyProject\MyProject\node_modules\node-sass\vendor\win32-x64-47\binding.node
Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 5.x
Found bindings for the following environments:
- Windows 64-bit with Node.js 6.x
This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass --force` to build the binding for your current environment.
at module.exports (C:\Work\MyProject\MyProject\node_modules\node-sass\lib\binding.js:15:13)
at Object.<anonymous> (C:\Work\MyProject\MyProject\node_modules\node-sass\lib\index.js:14:35)
at Module._compile (module.js:397:26)
at Object.Module._extensions..js (module.js:404:10)
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> (C:\Work\MyProject\MyProject\node_modules\gulp-sass\index.js:163:21)
at Module._compile (module.js:397:26)
I am running Node.js v6. I'm lost as to why what should be a simple process is giving me these errors. What am I doing wrong?
Update:
I ran the following commands suggested in the comments:
npm install node-sass -f
npm rebuild nose-sass
Both ran successfully. However, I'm still getting this error:
Failed to run "C:\Work\MyProject\MyProject\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
C:\Work\MyProject\MyProject\node_modules\gulp-sass\index.js:66
let sassMap;
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:404:10)
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> (C:\Work\MyProject\MyProject\gulpfile.js:8:12)
at Module._compile (module.js:397:26)
at Object.Module._extensions..js (module.js:404:10)
Update 2:
I was advised to add "use strict"; to the top of my gulpfile.js, but the same error occurs. Here's the file contents:
"use strict";
var gulp = require('gulp');
var sass = require('gulp-sass'); // If I comment this out, I can build
gulp.task('sass', function () {
gulp.src('src/css/**/*.scss')
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(gulp.dest('Content'));
});
Most common issue online appears to be Node.js version of < 6.0, but I'm running v6.11.1.
Update 3: (solved)
I finally found the cause & solution; I've added it as an answer down below for any future readers. Enjoy.
Managed to find the problem so I'm answering my own question for future readers.
Whilst I have node.js v6.11.1 installed, Visual Studio 2017 comes bundled with it's own version of node that it uses by default. Even if you run node -v in the VS2017 shell and it tells you it's running v6.11.1, it's actually - by default - running whatever it finds in .\node_mobules\.bin.
The solution is this:
In VS2017, go "Tools > Options > Projects and Solutions > Web Package Management > External Web Tools".
You'll probably see this:
Add the path to your standalone installation of node (default C:\Program Files\nodejs) and, using the arrows, position it above the .\node_modules\bin version, like this:
Hit OK and either refresh the Task Runner Explorer or restart VS2017. Your gulpfile should now build.
In my case, I had to move $(PATH) above $(VSINSTALLDIR)/Web/External to fix the problem.

NodeJs require function not working

I'm trying to include custom modules in my nodejs application. the problem that I'm facing is that whenever I try to include custom modules it says that it can't find that module.
Error: Cannot find module './queue/queue'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/contrive/tasweel/main.js :5: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)
I googled to find some solution but none of them worked. I transfered my project in another pc and there it was not throwing the error. After this I thought maybe there is some problem with node. So I uninstalled it and installed it again but it is still throwing me the same error.
Node Version: v6.9.1
Npm Version: 3.10.8
The way I'm trying to include the module is as followed below
var express = require('express');
var firebase = require("firebase");
var Queue = require('firebase-queue');
var queue = require('./queue/index'); // custom module (throwing error can't find module)
var queue = require('./index'); // custom module (throwing error can't find module)
var app = express();
OS: Ubuntu 16.04 64 bit
Folder structure:
-node-modules
-queue
-index.js
-worker.js
-main.js // entry point for node application
Please tell me why am I facing this error. Thanks

Some problems about the raw-socket in Node.js

My operating system is Windows 10 Version 10586 and node.js is Version 4.4.5.
When I use the module raw-socket follow the example in this page
https://github.com/stephenwvickers/node-raw-socket
When running code like this:
var raw = require ("raw-socket");
var socket = raw.createSocket ({protocol: raw.Protocol.None});
I got following error:
C:\Users\KEEY\node_modules\raw-socket\index.js:47
this.wrap = new raw.SocketWrap (
^
Error: ��һ�ַ���Ȩ�޲������ķ�ʽ����һ�������׽��ֵij��ԡ�
at Error (native)
at new Socket (C:\Users\KEEY\node_modules\raw-socket\index.js:47:14)
at Object.exports.createSocket (C:\Users\KEEY\node_modules\raw-socket\index.js:202:9)
at Object.<anonymous> (C:\Users\KEEY\Desktop\node\raw-socket\demo.js:2:18)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
[Finished in 0.2s with exit code 1]
How to solve it?
Thanks for everyone's help.
I email Stephen Vickers,the author of the module raw-socket,the source of problem is that
Stephen Vickers:
It looks like you don't have permissions to open raw sockets on that platform.
Then I run it as administrator, it works!
Thank you,Stephen Vickers
try this
var socket = raw.createSocket ({
protocol: raw.Protocol.None,
socketOption: raw.SocketOption.IPV6_HDRINCL
});

Crytip node.js error

$ node server.js
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object #<Object> has no method 'bodyDecoder'
at HTTPServer.<anonymous> (/home/jrg/Realtime-Demo/settings.js:20:18)
at HTTPServer.configure (/home/jrg/Realtime-Demo/node_modules/express/lib/http.js:543:61)
at Object.<anonymous> (/home/jrg/Realtime-Demo/settings.js:18:5)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at require (module.js:346:19)
at Object.<anonymous> (/home/jrg/Realtime-Demo/server.js:9:13)
at Module._compile (module.js:402:26)
When I try and run the Instagram node.js Realtime Demo project. The server is Ubuntu 10.04 (if that makes a difference, which I doubt).
This is not a duplicate of Express framework giving a very strange error - I tried the instructions there and they didn't work.
connect and express has bodyParser middleware, but not bodyDecoder.
It was renamed in the 1.0.0 version of the connect. It's a reason, why node.js projects must have package.json descriptor with dependences section, where components versions may be fixed.
You can install 0.5.10 version of connect or try to replace bodyDecoder with bodyParser

Resources