Gulp, vinyl-fs and error "TypeError: isStream is not a function" - node.js

I have a gulp file that up until relatively recently was working fine, but has started just throwing an error. I'm unsure of the best way to debug this, and google has not been of any help, so am looking for ideas on what might be wrong. The gulpfile has the following task defined (I've removed some other tasks to try and simplify this)
/// <binding AfterBuild='moveToCss' />
var gulp = require('gulp');
var paths = {
npmSrc: "./node_modules/",
cssTarget: "./wwwroot/css/",
};
var cssToMove = [
paths.npmSrc + '/bootstrap/dist/css/bootstrap.min.css',
paths.npmSrc + '/datatables.net-bs/css/dataTables.bootstrap.css',
paths.npmSrc + '/datatables.net-select-bs/css/select.bootstrap.css'
];
gulp.task('moveToCss', function () {
return gulp.src(cssToMove).pipe(gulp.dest(paths.cssTarget));
});
but when I run this I get the following error:
[13:52:27] Using gulpfile C:\MyProject\gulpfile.js
[13:52:27] Starting 'moveToCss'...
gulp : C:\MyProject\node_modules\gulp\node_modules\vinyl-fs\node_modules\vinyl\i
ndex.js:142
At line:1 char:1
+ gulp moveToCss >> result.txt 2>&1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (C:\MyProject\...yl\index.js:142:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
if (!isBuffer(val) && !isStream(val) && !isNull(val)) {
^
TypeError: isStream is not a function
at File.Object.defineProperty.set (C:\MyProject\node_modules\gulp\node_modul
es\vinyl-fs\node_modules\vinyl\index.js:142:28)
at new File (C:\MyProject\node_modules\gulp\node_modules\vinyl-fs\node_modul
es\vinyl\index.js:27:17)
at DestroyableTransform.createFile
(C:\MyProject\node_modules\gulp\node_modules\vinyl-fs\lib\src\index.js:12:12)
at DestroyableTransform.Transform._read (C:\MyProject\node_modules\gulp\node
_modules\readable-stream\lib\_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (C:\MyProject\node_modules\gulp\nod
e_modules\readable-stream\lib\_stream_transform.js:172:12)
at doWrite (C:\MyProject\node_modules\gulp\node_modules\readable-stream\lib\
_stream_writable.js:237:10)
at writeOrBuffer (C:\MyProject\node_modules\gulp\node_modules\readable-strea
m\lib\_stream_writable.js:227:5)
at DestroyableTransform.Writable.write (C:\MyProject\node_modules\gulp\node_
modules\readable-stream\lib\_stream_writable.js:194:11)
at Stream.ondata (stream.js:31:26)
at emitOne (events.js:77:13)
Can anyone suggest anything? Either ideas for what might be wrong or ideas for how to diagnose the issue...?

Since you seem to directly access files from the node_modules folder, the first thing I would try is to erase the entire node_modules folder and reinstall all dependencies in case you inadvertently fraked something up.
If that doesn't help the offending line is here. isStream comes from the ./lib/isStream module which does nothing more than export a function. How you can end up with a TypeError: isStream is not a function message in that context is a bit of a mystery to me.
The only thing I can think of that could be of help is to add some debugging output. In C:\MyProject\node_modules\gulp\node_modules\vinyl-fs\node_modules\vinyl\index.js add the following right before the offending if statement:
console.log(require('util').inspect(isStream, { showHidden: true, depth: null}));
That should at least tell us what type isStream is at the time the error is thrown.

Related

Impossible to install spookyjs

I want to install spookyjs and find it impossible to do so. I've tried three different ways:
Run the standard spookyjs package.json provided in spookyjs github.
Then I try to run hello.js and I am greeted with this error.
C:\Users\User1\Desktop\test2>node hello.js
events.js:183
throw er; // Unhandled 'error' event
^
Error: spawn casperjs ENOENT
at _errnoException (util.js:1022:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:695:11)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
Installed phantomjs and casperjs globally and package.json installed spooky and tiny-jsonrpc. I get the same error message.
Installed these dependencies from package.json
"dependencies": {
"spooky": "^0.2.5",
"tiny-jsonrpc": "^2.0.1",
"phantom": "^4.0.12",
"casperjs": "^1.1.4"
I get the same error.
I came across this link:
Issue
and it detailed the solution. That is this chunk of code:
const
path = require('path'),
_ = require('underscore')
;
var
// close env to pass to spawn
env = _.clone(process.env),
// get the PATH - in my local Windows, it was Path
envPath = env.PATH || env.Path,
// get path to node_modules folder where casperjs and
// phantomjs-prebuilt are installed
// this will be different for you
binDir = path.join(__dirname, './../../node_modules/.bin'),
Spooky = require('spooky')
;
// update the path in the cloned env
env.PATH = env.Path = `${envPath};${binDir}`;
var spooky = new Spooky({
child: {
// spooky is trying to call casperjs.bat for windows
// .bat doesn't work, so call the update .cmd file
// this fixes issue 2 with the file
command: /^win/.test(process.platform) ? 'casperjs.cmd' : 'casperjs',
transport: 'http' ,
spawnOptions: {
// set the env using cloned version
// this fixes issue 1 with the path
env: env
}
},
...
So now the program runs without an error. Actually though it runs without anything, because while on the one hand no error pops up, on the other nothing pops up. I debbuged by putting console.log() inside spooky's callback function but nothing is displayed. That is for another question though...
But the error i was receiving has vanished and the interpreter runs the code.

how to create a spritesheet using node-spritesheet?

I installed node-spritesheet and tried to create a spritesheet like this.
I created main.js and 3 images - image1.png, image2.png and image3.png in my home folder and in the same folder I've another folder called node-modules in which node modules like express, node-spritesheet etc. are present.
This's my main.js file
var Builder = require( 'node-spritesheet' ).Builder;
var builder = new Builder({
outputDirectory: '/home/XYZ',
outputImage: 'sprite.png',
outputCss: 'sprite.css',
selector: '.sprite',
images: [ 'image1.png', 'image2.png', 'image3.png' ]
});
builder.build( function() {
console.log( "Built from " + builder.files.length + " images" );
});
Next I ran
node main.js
which gave the following result
--------------------------------------------------------------
Building 'default' at pixel ratio 1
--------------------------------------------------------------
/home/XYZ/node_modules/node-spritesheet/lib/imagemagick.js:14
throw "Error in identify (" + filepath + "): " + (error || stderr);
^
Error in identify (image1.png): Error: Command failed: /bin/sh: 1: identify: not found
I tried different paths for image like ./image1.png, /home/XYZ/image1.png instead of just image1.png.
Can someone please explain why this's happening?
P.S : I'm new to node, so please excuse any silly mistakes I made and correct me.
The problem seems to be because the command identify isn't found, which is in imagemagick module. So it worked fine after installing imagemagick.

browserify watchify produces errors

I am using gulp, browserify and watchify. Here is my 'scripts' task:
gulp.task('scripts', function() {
var b = watchify(browserify(paths.app.root + '/client.js', watchify.args));
b.on('update', bundle);
return bundle();
function bundle() {
return b
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest(paths.build.root + '/scripts'));
}
});
client.js looks like:
require('request');
alert('1');
where request is node module (http client): https://github.com/request/request
When I run this task and execute the code - everything is fine. The problem starts when I change client.js. When I comment alert('1'), watchify start it's work and bundle() runs again. When I reload the page on the browser, I get the following javascript exception:
Uncaught TypeError: Cannot read property 'version' of undefined
with the following stack trace:
/Users/me/project/node_modules/browserify/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/elliptic/lib/elliptic.js.../package.jsonbundle.js:19825
/Users/me/project/node_modules/browserify/node_modules/crypto-browserify/node_modules/create-ecdh/node_modules/elliptic/lib/elliptic.js.../package.jsonbundle.js:1
/Users/me/project/node_modules/browserify/node_modules/crypto-browserify/node_modules/create-ecdh/ecdh.js.bn.js
/Users/me/project/node_modules/browserify/node_modules/crypto-browserify/node_modules/create-ecdh/inject.js../ecdh
/Users/me/project/node_modules/browserify/node_modules/crypto-browserify/index.js.browserify-aes
/Users/me/project/node_modules/request/lib/helpers.js._process
/Users/me/project/node_modules/request/index.js../lib/cookies
./client.js.request
Any idea what is wrong with browserify / request?
It looks like it is an issue with elliptic, a dependency of browserify. See https://github.com/indutny/elliptic/issues/30
Hopefully this gets fixed up shortly.
Edit: It may actually be an issue with browserify. I would try reverting to 8.1.2 and seeing if that helps.

Node debug - undefined error

I was exploring node debugger and I am stuck at the problem. I have a debugging.js file with following content
var http = require("http");
function process_request(req, res) {
var body = 'Thanks for calling!\n';
var content_length = body.lenggth ;
res.writeHead(200, {
'Content-Length': content_length,
'Content-Type': 'text/plain'
});
res.end(body);
}
var s = http.createServer(process_request);
s.listen(8080);
Note that there is an mistake on line 5. This is done intentionally to debug the problem. Now I tried running node using node debug debugging.js. While this didn't gave any error. Calling setBreakpoint(5) resulted in following error.
Warning: script 'undefined' was not loaded yet.
_debugger.js:1399
var escapedPath = script.replace(/([/\\.?*()^${}|[\]])/g, '\\$1');
^
TypeError: Cannot call method 'replace' of undefined
at Interface.setBreakpoint (_debugger.js:1399:31)
at repl:1:1
...
Environment : Debian Linux3.2.0, Node JS - V0.13.0-pre
Can someone tell me, what should be done to resolve this?
I found post, which seems to have similar problem, but it seems to be a year old post and I am not sure whether the fix is available in the node version, I am using.
Well it seems to be a problem with the node V0.13.0-pre, I am using on Linux. I tried same code on Windows with node v0.10.33 and its working well. All the debugging commands are working as expected.

node.js mkdir enonent when passed a string

I'm trying to build folders with a string, but I keep erroring out, everything looks good, but I'm obviously missing something, any help would be great.
var setFile = 'dijit/analysis/images/'
folders = setFile.substr(0,setFile.lastIndexOf('/'));
fs.mkdir(folders, function(err){
console.log('problem: ' + err);
});
Error: Error: ENOENT, mkdir 'dijit/analysis/images'
Thanks,
fs.mkdir can able to built only a single folder. You are trying to create a folder inside a non existing folder. This problem can be solved by fs-extra module of npm. Following code should fulfill your need.
var setFile = 'dijit/analysis/images/',
fsExtra = require('fs-extra'),
folders = setFile.substr(0, setFile.lastIndexOf('/'));
fsExtra.mkdirp(folders, function(err) {
console.log('problem: ' + err);
});
Kundu's comment answers this problem, but if you want a different solution there is plenty over at How to create full path with node's fs.mkdirSync?

Resources