Getting error while using Imagemagick npm - node.js

I am using Imagemagick npm in node to compress an image. I installed the npm module and it was working fine. But after some time, it throws the error shown below.
TypeError: currentLine.search is not a function
If I install the module again, it doesn't show the error. But again after some time, it throws the same error. I am using 0.1.3 version of Imagemagick with 8.9.1 version of node.
Can any one help me with this issue?

Even I got the same issue for 0.1.3 npm version. After some debugging, I found that if we add custom functions into Array.prototype like this
Array.prototype.asyncforEach = async function(cbk) {
for (let i = 0; i < this.length; i++) await cbk(this[i], i, this);
};
Which will leads to an error in file node_modules/imagemagick/imagemagick.js at line number 113 i will have asyncforEach as a value so we have to change our Array.prototype.methodName like below or reference this for better understanding.
Object.defineProperty(Array.prototype, 'asyncforEach', {
value: async function(cbk) {
for (let i = 0; i < this.length; i++) await cbk(this[i], i, this);
}
});

Related

Uncaught TypeError: Object.values is not a function

Okay so, I npm run build my application, drag the build files into tizon studio.
Run the application...
I get the error:
2.bd938b3f.chunk.js:79798 Uncaught TypeError: Object.values is not a function
The same behavior is shown on any Samsung and Tizon model I've tested this on.
I've tried switching out Object.values with Object.map,
which returns "the same" error.
2.bd938b3f.chunk.js:79798 Uncaught TypeError: Object.map is not a function
I have not been able to find an answer to fix this.
Any help with finding an answer would be massively appreciated.
Thank you all in advance!
if (!le) {
(function () {
for (var e = window.document.getElementsByTagName("script"), t = 0, n = Object.values(e); t < n.length; t++) {
var r = n[t];
if (r.src && r.src.includes(te))
return r
}
return null
})() || function (e) {
var t = document.createElement("script");
t.src = te + "?l=" + e,
t.async = !0,
document.head.appendChild(t)
}
(ue),
function (e) {
var t = [];
Array.isArray(window[e]) ? t = window[e] : window[e] = t
}
(ue);
var r = ne(se, ue, ce),
i = r.wrappedGtag,
a = r.gtagCore;
ie = i,
re = a,
le = !0
}
Samsung's TizenOS's javascript isn't as up-to-date as it could be, and according to this looks to not be actively supported.
You can use react-app-polyfill to provide any missing functionalities.
We use the following in our root index.jsx as the "kitchen sink" of polyfills
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/stable';
It seems Object.values() is not supported in your developing environment. Try adding this polyfill on top of your script file: https://github.com/tc39/proposal-object-values-entries/blob/master/polyfill.js
You can define your own values function if the node version is too low.
if (!Object.values) {
Object.values = function values(O) {
return Object.keys(O).map(k=>O[k]);
};
}

How to fix: Error: If .NET source is provided as JavaScript function, function body must be a /* ... */ comment

I am trying to run the basic hello world example from the documentation from here (it's the first example on the page):
https://github.com/agracio/edge-js
I have a typescript file that I am running (see the code below). I am on node version 9.9.0 on a Windows 10 64 bit. I have made only the following installations:
npm install edge
npm install edge.js
npm install #types/node --save-dev
I have made the installations to the same directory as the typescript file.
I am able to run ts-node app.ts in the command line and have it console.log("hi") successfully in that directory.
However, when I change my code to the example below, it is giving me the error throw new Error('If .NET source is provided as JavaScript function, function body must be a /* ... */ comment.');
I had originally tried doing this using edge.js but I kept getting the error that I needed to precompile. For the life of me I couldn't get it to find my python executable when executing build.bat release 10.5.3. (Despite including an environment variable PYTHON with a value of c:\Python\Python37\python.exe) I wanted to try using edge-js because it was already precompiled. I downgraded node to 9.9 (I uninstalled node 10.15.3 and then installed the 9.9.0 msi from the website) because I thought edge-js only supported version 9. Well here I am trying to run edge-js with version 9 and I am still getting an error, although it is a different error.
Here is the code I am trying to run:
var edge = require('edge-js');
var helloWorld = edge.func(function () {/*
async (input) => {
return ".NET Welcomes " + input.ToString();
}
*/});
helloWorld('JavaScript', function (error, result) {
if (error) throw error;
console.log(result);
});
I can't believe this worked. It was a syntax error. A problem with the amount of whitespace between the comment and the end of the function. Here is the correct syntax:
var edge = require('edge-js');
var helloWorld = edge.func(function () {
/*async (input) => {
return ".NET Welcomes " + input.ToString();
}*/
});
helloWorld('JavaScript', function (error, result) {
if (error) throw error;
console.log(result);
});

node require.cache delete does not result in reload of module

I'm writing tests for my npm module.
These tests require to install multiple versions of an npm module in order to check if the module will validate them as compatible or incompatible.
Somehow all uncache libraries or function I found on stackoverflow or the npm database are not working..
I install/uninstall npm modules by using my helper functions:
function _run_cmd(cmd, args) {
return new Promise((res, rej) => {
const child = spawn(cmd, args)
let resp = ''
child.stdout.on('data', function (buffer) {
resp += buffer.toString()
})
child.stdout.on('end', function() {
res(resp)
})
child.stdout.on('error', (err) => rej(err))
})
}
global.helper = {
npm: {
install: function (module) {
return _run_cmd('npm', ['install', module])
},
uninstall: function (module) {
decacheModule(module)
return _run_cmd('npm', ['uninstall', module])
}
}
}
This is my current decache function which should clear all modules caches (I tried others, including npm modules none of them worked)
function decacheModules() {
Object.keys(require.cache).forEach(function(key) {
delete require.cache[key]
})
}
I am installing multiple versions of the less module (https://www.npmjs.com/package/less)
In my first test I am installing a deprecated version which does not have a render-function.
In some other test I am installing an up-to-date version which has the render-function. Somehow if I test for that function that test does fail.
If I skip the first test the other test succeeds. (render-function exists).
This makes me believe that the deletion of require.cache has no impact...
I am using node v4.2.4.
If there is a reference to the old module:
var less = require('less');
Clear module cache will not lead that reference cleared and reload the module.
For that to work, at least you don't store module to variable, use the "require('less')" in place everywhere.

Browserify cannot find installed module sha3

I am working on ethereumjs-libpackage installed from npm which has a dependency on sha3 module. However browserify is not able to pick it up from the dependencies. I installed sha3 manually and wrote the simple code shown below, still browserify shows me the error Cannot find module 'sha3'
var unique = require('uniq');
var sha = require('sha3');
var data =[1,2,2,3,4,5,5,5,6];
var uniqueArray = unique(data);
for(var i = 0; i < uniqueArray.length ; i++){
console.log(uniqueArray[i]);
}

Generator functions in node 0.12

Are generator functions supported in Node? I keep reading that they are since v 0.11.
Tried to run this snippet in node 0.12
function* range(max, step) {
var count = 0;
step = step || 1;
for (var i = 0; i < max; i += step) {
count++;
yield i;
}
return count;
}
but no luck. Do I need to call npm start with a custom parameter?
You need to run node with --harmony flag to enable generators in node (0.11.x and 0.12.x versions):
$ node --harmony your_script.js

Resources