Grunt - no image library that works. All are silently failing - javascript

I'm grunt beginner. But whenever I install any kind of grunt library to handle images it does not work.
grunt-webshot, webshot, getPixels, node-image, node, gm, node-pngjs, imagemagick, node-png, png, get-pixels
grunt.registerTask("getPixels", "your description", function() {
var fs = require('fs') , gm = require('gm');
gm('source/templates/t1/images/menu_item_bg.png').size(function (err, size) {
grunt.log.writeln(size.width > size.height ? 'wider' : 'taller than you');
});
});
Silently fails. No error, no nothing (I get: Done, without errors). Does not enter callback.
Same is with other libraries I used.
Only grunt modules can be used in grunt? Dont Think so, it seems i can use any library by using require() and it should work. It works ok with require('path')
Any way I can debug it? Make it return some kind of error or fix this problem?
Edit
I wrote a makescreenshot.js script which I call with node
var webshot = require('webshot');
// also tried commented varians:
//webshot('google.com', 'google.jpg', function(err) {
//webshot('http://google.com', 'google.jpg', function(err) {
webshot('http://google.com', 'google.jpg', {}, function(err) {
console.log('console.log ERROR: ' + err);
});
It returns the following: console.log ERROR: Error: PhantomJS exited with return value 1

Seems I figured it somehow. The problem seemed to be not properly installed Microsoft Visual Studio I reinstalled MSVS 2013 Express and it started taking screens normally.

Related

Next js. error - unhandledRejection: Error: File './script.php' not found

there! I am developing app with Next js. and i need to run php script to get some value.
For executing php code I use '"exec-php' package from npm. this package requires enter php file path to js function. But when I put path as parameter to function and call this function, next js throws error - unhandledRejection: Error: File './script.php' not found.
execPhp('./script.php', (err, php, out) => {
php.test(obj, process.env.KEY, (err, result, output, printed) => {
signature = result;
});
});
If you have idea how to solve please answer. Thanks~

Node.js 'fs' throws an ENOENT error after adding auto-generated Swagger server code

Preamble
To start off, I'm not a developer; I'm just an analyst / product owner with time on their hands. While my team's actual developers have been busy finishing off projects before year-end I've been attempting to put together a very basic API server in Node.js for something we will look at next year.
I used Swagger to build an API spec and then used the Swagger code generator to get a basic Node.js server. The full code is near the bottom of this question.
The Problem
I'm coming across an issue when writing out to a log file using the fs module. I know that the ENOENT error is usually down to just specifying a path incorrectly, but the behaviour doesn't occur when I comment out the Swagger portion of the automatically generated code. (I took the logging code directly out of another tool I built in Node.js, so I'm fairly confident in that portion at least...)
When executing npm start, a few debugging items write to the console:
"Node Server Starting......
Current Directory:/mnt/c/Users/USER/Repositories/PROJECT/api
Trying to log data now!
Mock mode: disabled
PostgreSQL Pool created successfully
Your server is listening on port 3100 (http://localhost:3100)
Swagger-ui is available on http://localhost:3100/docs"
but then fs throws an ENOENT error:
events.js:174
throw er; // Unhandled 'error' event
^
Error: ENOENT: no such file or directory, open '../logs/logEvents2021-12-24.log'
Emitted 'error' event at:
at lazyFs.open (internal/fs/streams.js:277:12)
at FSReqWrap.args [as oncomplete] (fs.js:140:20)
Investigating
Now normally, from what I understand, this would just mean I've got the paths wrong. However, the file has actually been created and the first line of the log file has been written just fine
My next thought was that I must've set the fs flags incorrectly, but it was set to 'a' for append:
var logsFile = fs.createWriteStream(__logdir+"/logEvents"+dateNow()+'.log',{flags: 'a'},(err) =>{
console.error('Could not write new Log File to location: %s \nWith error description: %s',__logdir, err);
});
Removing Swagger Code
Now here's the weird bit: if I remove the Swagger code, the log files write out just fine and I don't get the fs exception!
This is the specific Swagger code:
// swaggerRouter configuration
var options = {
routing: {
controllers: path.join(__dirname, './controllers')
},
};
var expressAppConfig = oas3Tools.expressAppConfig(path.join(__dirname, '/api/openapi.yaml'), options);
var app = expressAppConfig.getApp();
// Initialize the Swagger middleware
http.createServer(app).listen(serverPort, function () {
console.info('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort);
console.info('Swagger-ui is available on http://localhost:%d/docs', serverPort);
}).on('error',console.error);
When I comment out this code, the log file writes out just fine.
The only thing I can think that might be happening is that somehow Swagger is modifying (?) the app's working directory so that fs no longer finds the same file?
Full Code
'use strict';
var path = require('path');
var fs = require('fs');
var http = require('http');
var oas3Tools = require('oas3-tools');
var serverPort = 3100;
// I am specifically tried using path.join that I found when investigating this issue, and referencing the app path, but to no avail
const __logdir = path.join(__dirname,'./logs');
//These are date and time functions I use to add timestamps to the logs
function dateNow(){
var dateNow = new Date().toISOString().slice(0,10).toString();
return dateNow
}
function rightNow(){
var timeNow = new Date().toTimeString().slice(0,8).toString();
return "["+timeNow+"] "
};
console.info("Node Server Starting......");
console.info("Current Directory: " + __dirname)
// Here I create the WriteStreams
var logsFile = fs.createWriteStream(__logdir+"/logEvents"+dateNow()+'.log',{flags: 'a'},(err) =>{
console.error('Could not write new Log File to location: %s \nWith error description: %s',__logdir, err);
});
var errorsFile = fs.createWriteStream(__logdir+"/errorEvents"+dateNow()+'.log',{flags: 'a'},(err) =>{
console.error('Could not write new Error Log File to location: %s \nWith error description: %s',__logdir, err);
});
// And create an additional console to write data out:
const Console = require('console').Console;
var logOut = new Console(logsFile,errorsFile);
console.info("Trying to log data now!") // Debugging logging
logOut.log("========== Server Startup Initiated ==========");
logOut.log(rightNow() + "Server Directory: "+ __dirname);
logOut.log(rightNow() + "Logs directory: "+__logdir);
// Here is the Swagger portion that seems to create the behaviour.
// It is unedited from the Swagger Code-Gen tool
// swaggerRouter configuration
var options = {
routing: {
controllers: path.join(__dirname, './controllers')
},
};
var expressAppConfig = oas3Tools.expressAppConfig(path.join(__dirname, '/api/openapi.yaml'), options);
var app = expressAppConfig.getApp();
// Initialize the Swagger middleware
http.createServer(app).listen(serverPort, function () {
console.info('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort);
console.info('Swagger-ui is available on http://localhost:%d/docs', serverPort);
}).on('error',console.error);
In case it helps, this is the project's file structure . I am running this project within a WSL instance in VSCode on Windows, same as I have with other projects using fs.
Is anyone able to help me understand why fs can write the first log line but then break once the Swagger code gets going? Have I done something incredibly stupid?
Appreciate the help, thanks!
Edit: Tried to fix broken images.
Found the problem with some help from a friend. The issue boiled down to a lack of understanding of how the Swagger module works in the background, so this will likely be eye-rollingly obvious to most, but keeping this post around in case anyone else comes across this down the line.
So it seems that as part of the Swagger initialisation, any scripts within the utils folder will also be executed. I would not have picked up on this if it wasn't pointed out to me that in the middle of the console output there was a reference to some PostgreSQL code, even though I had taken all reference to it out of the main index.js file.
That's when I realised that the error wasn't actually being generated from the code posted above: it was being thrown from to that folder.
So I guess the answer is don't add stuff to the utils folder, but if you do, always add a bunch of console logging...

Error: write EPIPE on sendFile()?

I'm using the html-pdf module to generate pdfs, using the following code:
var ejs = require('ejs');
var fs = require('fs');
var pdf = require('html-pdf');
var build = function (template, data) {
var html = ejs.compile(fs.readFileSync(template, 'utf8'));
html = html(data);
return html;
}
pdf.create(build('views/print_templates/pm_export_pdf.ejs',
{rows:resolve(rows, user_rows, table_rows,
subproject_rows, milestone_rows, release_rows)}), pdfconfig)
.toFile(function (err, pdf) {
if (err)
return console.log(err);
res.sendFile(pdf.filename);
});
PDFconfig is the config variable for html-pdf. And resolve is my own db resolve function, which is not very relevant in this story.
When I run this locally on OSX 10.10 on my MacBook Pro this works like a charm. But when I run this on my server(centOS), I get the following error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at errnoException (net.js:904:11)
at Object.afterWrite (net.js:720:19)
Has this something to do with permissions maybe? I'm not really sure what I'm doing wrong..
I run the following versions:
Node: 0.10.31
Express: 4.10.7
html-pdf: 1.2.0
For future purposes:
I figured that I had to rebuild my node-modules. I think I accidentally copied the node-modules folder over to the test server on centOS, and phantomjs had build it's dependencies for OSX. I'm still not sure how the error that it threw correspondents with that, but it fixed it.
Also be sure that you have FreeType and fontconfiglib installed.

'WebSocket.URL' is deprecated. Please use 'WebSocket.url' instead

WebSocket connection to 'ws://localhost:35729/livereload' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED chromereload.js:9
'WebSocket.URL' is deprecated. Please use 'WebSocket.url' instead. chromereload.js:12
I'm getting this error message in my chrome extension since chrome updated to version 38. I'm not quite sure whats going on here, but now opening most things causes the extension to crash. I used yeoman to scaffold my project at the beginning, and everything was working fine. I tried removing livereload from the manifest, but that seems to break everything. Any help would be appreciated.
Here is the code:
'use strict';
// Reload client for Chrome Apps & Extensions.
// The reload client has a compatibility with livereload.
// WARNING: only supports reload command.
var LIVERELOAD_HOST = 'localhost:';
var LIVERELOAD_PORT = 35729;
var connection = new WebSocket('ws://' + LIVERELOAD_HOST + LIVERELOAD_PORT + '/livereload');
connection.onerror = function (error) {
console.log('reload connection got error' + JSON.stringify(error));
};
connection.onmessage = function (e) {
if (e.data) {
var data = JSON.parse(e.data);
if (data && data.command === 'reload') {
chrome.runtime.reload();
}
}
};
In Chrome this message is emitted when using something like JSON.stringify() or similar on a WebSocket object. These kind of routines will access the WebSocket.URL property, which is deprecated, and emit this warning. Even if your code doesn't explicitly call WebSocket.URL. You can delete this property to mute the warning from Chrome.
var ws = new WebSocket('wss://example.com/');
delete ws.URL;
console.log(JSON.stringify(ws));

uncaught reference error: FileTransfer not defined at cordova.js(3.0.0)

I am bulding a simple cross platform app using cordova 3.0.0. The installation went fine. But I cannot seem to get the file transfer to work. I keep getting this error.
processMessage failed: Error: ReferenceError: FileTransfer is not defined at file:///android_asset/www/cordova.js:1035
I have installed all the plugins properly and also calling device ready as such:
function onLoad(){
document.addEventListener("deviceready",onDeviceReady,false);
}
My code is as follows:
function uploadFileForCapture(mediaFile) {
var ftforcapture = new FileTransfer(),
path = mediaFile.fullPath,
name = mediaFile.name;
alert(path + name);
ftforcapture.upload(path,
"http:/some.server.com/upload.php",
function(result) {
alert('Upload success: ' + result.responseCode);
alert(result.bytesSent + ' bytes sent');
},
function(error) {
alert('Error uploading file ' + path + ': ' + error.code);
},
{ fileName: name });
}
Can some one please help!
Thanks a lot in advance!
I ran into this error as well. For me the file transfer plugin was never successfully installed. It was not in the android platform folder with the other plugins that I was using. I was installing with the cli client. I created a fresh project and noticed that when I ran this cordova plugin add command that I received this error.
[TypeError: Arguments to path.join must be strings]
I tried a clean install on a virtual machine expecting it to be something in my setup but it still didn't work. Before I could file a bug report on it, Cordova 3.1.0 was released. I created my project over and this time the file transfer plugin was successfully installed.

Categories

Resources