code: 'ENOENT', message: 'No such file or directory' when using opencv.js in node-project - node.js

I'm using opencv.js for face detection. When I run this html file with the linked js files (opecv.js,utils.js) using a live server, it works.But,now when I copy the same files in my node project,and render this html page, I get the following error.
Uncaught
ErrnoError {node: undefined, errno: 2, code: 'ENOENT', message: 'No such file or directory', setErrno: ƒ, …}
code: "ENOENT"
errno: 2
message: "No such file or directory"
node: undefined
setErrno: ƒ (errno)
arguments: null
caller: null
length: 1
name: ""
prototype: {constructor: ƒ}
[[FunctionLocation]]: opencv.js:24
[[Prototype]]: ƒ ()
[[Scopes]]: Scopes[4]
stack: "<generic error, no stack>"
[[Prototype]]: Error at Object.ensureErrnoError (http://127.0.0.1:3000/js/opencv.js:24:8492014) at Object.staticInit (http://127.0.0.1:3000/js/opencv.js:24:8492254) at http:

Related

Using laravel browsershot

I installed Browsershot and I'm taking google's image to test it. I prepared the route but it gives an unexpected error.
Symfony\Component\Process\Exception\ProcessFailedException
The command "C:^\nodejs^\node ^"C:^\Users^\AT08877^\it-graph^\vendor^\spatie^\browsershot^\src/../bin/browser.js^" ^"^{^^"url^^":^^"http:^/^/127.0.0.1:8000^/chart^^",^^"action^^":^^"screenshot^^",^^"options^^":^{^^"type^^":^^"png^^",^^"path^^":^^"C:^^\Users^^\AT08877^^\it-graph^^\public^^\deneme.png^^",^^"args^^":^[^],^^"viewport^^":^{^^"width^^":800,^^"height^^":600^}^}^}^"" failed. Exit Code: 1(General error) Working directory: C:\Users\AT08877\it-graph\public Output: ================ Error Output: ================ [Error: ENOENT: no such file or directory, mkdtemp 'undefined\temp\puppeteer_dev_chrome_profile-XXXXXX'] { errno: -4058, code: 'ENOENT', syscall: 'mkdtemp', path: 'undefined\temp\puppeteer_dev_chrome_profile-XXXXXX' }
Route::get('/test',function ()
{
$browser = Browsershot::url('www.google.com')
->setNodeBinary("'C:\Program Files\nodejs\node'")
->setNpmBinary("'C:\Program Files\nodejs\node'")
->bodyHtml();
dd($browser);
});

child_process.spawnSync error 'ENOENT' when unzipping a file

I'm trying to execute a cli command using child_process.spawnSync to unzip a file, but when I run the code it says ENOENT even though the command works fine.
const result = spawnSync(`unzip ${path}`, [
passwordArg, // ''
outputArg, // ''
]);
// console.log(result)
error: Error: spawnSync unzip /<...>/unzipFiles/test/zipp.zip ENOENT
...
errno: -2,
code: 'ENOENT',
syscall: 'spawnSync unzip /<...>/unzipFiles/test/zipp.zip',
path: 'unzip /<...>/unzipFiles/test/zipp.zip',
spawnargs: ['', '']
If I copy and paste and execute the exact value for path, i.e. unzip /<...>/unzipFiles/test/zipp.zip, it runs as expected.
Any help would be much appreciated.

Is There a way to get the full path of file dependencies in Madge API?

I'm using Magde API (https://github.com/pahen/madge/blob/master/README.md) to generate the dependency graph of my JS file...
Once the dependencies are return as object, the file paths are not clearly documented... I was wondering if there exists a way to tell Madge to specify the full path not the cut it
I want to get the dependencies of this file:
import * as t from 'C:/Users/Tec/todolist_example_jest/req2.js';
function formatName(user) {
return user.firstName + ' ' + user.lastName;
}
const element = (
<h1>
Hello, {formatName(user)}!
</h1>
);
const user = {
firstName: 'Harper',
lastName: 'Perez'
};
As we can see there exists a dependency on this file:
'C:/Users/Tec/todolist_example_jest/req2.js'; But when using madge to get the dependencies ... look below to see what is the output
Here is the code snippet:
madge('file path').then((res) => {
dependencies = res.obj(); // the dependencies as an object
console.log(dependencies);
});
and this is the output:
{
'../../../../todolist_example_jest/req2.js': [],
'simpleElement.jsx': [ '../../../../todolist_example_jest/req2.js' ]
}
../../../../todolist_example_jest/req2.js
node:fs:585
handleErrorFromBinding(ctx);
^
Error: ENOENT: no such file or directory, open '../../../../todolist_example_jest/req2.js'
at Object.openSync (node:fs:585:3)
at Object.readFileSync (node:fs:453:35)
at C:\Users\Tec\React Native Applications\Upload-main\backend\app.js:47:27
at Array.forEach (<anonymous>)
at C:\Users\Tec\React Native Applications\Upload-main\backend\app.js:44:33 {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: '../../../../todolist_example_jest/req2.js'
}

I got error while validating field in mongodb, nodejs

These are the errors I got from backend while validating in model and received in 'err' variable. If I console.log(err), then it shows following errors.
Error [ValidationError]: employees validation failed: fullName: This field is required from model, email: This field is required from model
at ValidationError.inspect (D:\Programming\MERN\CRUD\node_modules\mongoose\lib\error\validation.js:61:24)
at formatValue (internal/util/inspect.js:703:31)
at inspect (internal/util/inspect.js:272:10)
at formatWithOptions (internal/util/inspect.js:1887:40)
at Object.Console.<computed> (internal/console/constructor.js:284:10)
at Object.log (internal/console/constructor.js:294:61)
at handleValidationError (D:\Programming\MERN\CRUD\routes\/employeeRoute.js:46:13)
at D:\Programming\MERN\CRUD\routes\/employeeRoute.js:33:17
at D:\Programming\MERN\CRUD\node_modules\mongoose\lib\model.js:4915:16
at D:\Programming\MERN\CRUD\node_modules\mongoose\lib\helpers\promiseOrCallback.js:16:11
at D:\Programming\MERN\CRUD\node_modules\mongoose\lib\model.js:4938:21
at D:\Programming\MERN\CRUD\node_modules\mongoose\lib\model.js:492:16
at D:\Programming\MERN\CRUD\node_modules\kareem\index.js:246:48
at next (D:\Programming\MERN\CRUD\node_modules\kareem\index.js:167:27)
at next (D:\Programming\MERN\CRUD\node_modules\kareem\index.js:169:9)
at Kareem.execPost (D:\Programming\MERN\CRUD\node_modules\kareem\index.js:217:3) {
errors: {
fullName: MongooseError [ValidatorError]: This field is required from model
at new ValidatorError (D:\Programming\MERN\CRUD\node_modules\mongoose\lib\error\validator.js:29:11)
at validate (D:\Programming\MERN\CRUD\node_modules\mongoose\lib\schematype.js:1178:13)
at D:\Programming\MERN\CRUD\node_modules\mongoose\lib\schematype.js:1161:7
at Array.forEach (<anonymous>)
at SchemaString.SchemaType.doValidate (D:\Programming\MERN\CRUD\node_modules\mongoose\lib\schematype.js:1106:14)
at D:\Programming\MERN\CRUD\node_modules\mongoose\lib\document.js:2378:18
at processTicksAndRejections (internal/process/task_queues.js:79:11) {
properties: [Object],
kind: 'required',
path: 'fullName',
value: '',
reason: undefined,
[Symbol(mongoose:validatorError)]: true
},
email: MongooseError [ValidatorError]: This field is required from model
at new ValidatorError (D:\Programming\MERN\CRUD\node_modules\mongoose\lib\error\validator.js:29:11)
at validate (D:\Programming\MERN\CRUD\node_modules\mongoose\lib\schematype.js:1178:13)
at D:\Programming\MERN\CRUD\node_modules\mongoose\lib\schematype.js:1161:7
at Array.forEach (<anonymous>)
at SchemaString.SchemaType.doValidate (D:\Programming\MERN\CRUD\node_modules\mongoose\lib\schematype.js:1106:14)
at D:\Programming\MERN\CRUD\node_modules\mongoose\lib\document.js:2378:18
at processTicksAndRejections (internal/process/task_queues.js:79:11) {
properties: [Object],
kind: 'required',
path: 'email',
value: '',
reason: undefined,
[Symbol(mongoose:validatorError)]: true
}
},
_message: 'employees validation failed'
}
Now if I console.log('err.errors.fullName.message'). It works perfectly.
But if there are more keys, it's obvious that we need to use loop. So if I try to iterate through keys of object as follow, then it throws following error.
for(field in err.errors){
.......
.......
}
Error is:
ReferenceError: field is not defined
What's the problem here ?
First of all your backend should not give this type of error response as you mentioned in the above. This must be like a JSON response of errors. e.g
{ success: false, errors: [{fullName: "fullName is required"}] }
Coming to your question. If you want to show error properly you can loop through the error which you can pic by the err.errors
eg err.errors.forEach(error => console.log(error) )
But again this is a very wrong way to throw the validation error. To validate any data you can use joi, request-validator, validatorjs, etc. Which will give you a perfect error response as you want? Why I am giving stress on this because you are exposing entire directory, files, model name, etc.
I hope this may help you to solve your problem

fs.unlink EBUSY error

I am trying to delete a file in nodejs. When I run the following code:
try {
fs.unlinkSync('file');
} catch(e) {
console.log(e)
}
I get the following error.
Error: EBUSY: resource busy or locked, unlink '<redacted>'
at Object.fs.unlinkSync (fs.js:1067:18)
at Function.rimrafSync [as sync] (<redacted>\node_modules\rimraf\rimraf.js:306:17)
at <redacted>:74:10
at Array.forEach (<anonymous>)
at Function.module.exports.sync (<redacted>\node_modules\node-delete\index.js:67:30)
at <filepath>:4145:46
at Array.forEach (<anonymous>)
at <redacted>:4142:21
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
errno: -4082,
code: 'EBUSY',
syscall: 'unlink',
path: '<redacted>'
This error means the file you're trying to delete is currently in use or locked.
Without providing more informations we will guess, that the file you are trying to delete is locked by another program. Please check this...

Resources