I tryed to use tesseract.js in a node server so I can do some ocr on
some invoices. I did what the docs say regarding the
instalation but after I
tryed the sample code it's like everything is hanging and I don't get
any feedback in the console.
Here is what I did
Install
npm install --save tesseract.js
Code
Tesseract.recognize(buffer, {
lang: 'eng',
})
.progress(message => console.log('progress is: ', message))
.catch(err => {
console.error(`\r\n ERROD =>`, err, `\r\n`);
reject(err);
})
.then(result => {
console.log(`\r\n SUCCESS =>`, result, `\r\n`);
resolve(result);
})
.finally(resultOrError => {
console.log(`\r\n FINALLY =>`, resultOrError, `\r\n`);
});
I don't get any reponse and the console does not print anything. Do I
need to install also something else ? Note I thaught the tesseract
ocr needs to be installed so I tryed also to do this.
brew install tesseract
But still no response from the package, did anyone encounter this ?
Node version - 8.11.2
Related
I am sending my data to MongoDB via Mongoose. Now, during the fetch of API route for it, an error is thrown.
Code
const addChoice = async (e) => {
try {
e.preventDefault();
const res = await fetch("/api/sendChoice", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
choiceSeq: choice,
checkSubmit: true,
}),
});
console.log(res);
router.push("/home");
} catch (error) {
console.log(error);
}
};
The error is happening at const res = await fetch("/api/sendChoice" ,{
In terminal server the error
error - TypeError: Cannot assign to read only property 'map' of object
'#<QueryCursor>'
In the inspect element the error is as
I can't find anything related to fix this issue, I don't even understand what the error means to try to resolve it myself.
Some other related code from my project:
api/sendChoice
import { getSession } from "next-auth/client";
import dbConnect from "../../helpers/dbConnect";
import Choice from "../../models/Choice";
export default async function sendChoice(req, res) {
try {
const session = await getSession({ req });
await dbConnect();
if (!session) {
res.status(401).send("You are not signed in");
return;
}
if (req.method === "POST") {
console.log(req.body);
const { choiceSeq, checkSubmit } = req.body;
console.log(choiceSeq, checkSubmit);
const userId = session.user.id;
const nameP = session.user.name;
const choice = new Choice({
user: userId,
name: nameP,
choiceSeq,
checkSubmit,
});
await choice.save();
res.status(200).send("Choice saved");
} else {
res.status(400).send("Bad request");
}
}
catch (error) {
console.log(error);
}
}
The MongoDB schema
import mongoose, { Schema } from 'mongoose';
const ChoiceSchema = new Schema({
user: {
type: Schema.Types.ObjectId,
ref: 'User',
},
name: {
type: String,
},
choiceSeq: {
type: Array,
default: [],
},
checkSubmit: {
type: Boolean,
}
});
mongoose.models = {};
export default mongoose.model('Choice', ChoiceSchema);
the latest update to version 17.5.0 is the one causing this error. You must reinstall node js to version 16.14.0 LTS. You should always work with LTS versions
This issue occured recently and apparently its happening with latest version of node.
issue link
So you can change the version of node to older version and it will be fixed. I am using node version v14.19.0
if you are using Docker then, giving a version will solve the problem.
before:
FROM node:alpine
now
FROM node:16.5.0-alpine
WORKDIR /app
COPY package.json .
RUN npm install --only=prod
COPY . .
CMD ["npm", "start"]
The latest release of Node.JS is what is causing this issue. In your package.json, make sure to set your engine to"engines": { "node": ">=0.12 < 17.5.0" } and you should be fine.
Also if you are using docker for deployment, make sure to change the version number in your dockerfile to be less that 17.5.0
Solution which worked well for me:)
Step 01: Open your terminal and copy paste below command.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | zsh
Wait patiently until its done.
Step 02: sudo vim ./zshrc
Step 03: Press I for Insert Mode and copy paste below command. Must be same in three lines.
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"
then press ESC key :wq (write and quite).
Step 04: brew install nvm
step 05: nvm install node (which will download latest version node)
step 06: nvm ls-remote (which make all the version available)
step 07: nvm install 14 (An Example)
step 08: nvm use 14 (this make it as default version)
source: https://github.com/nvm-sh/nvm
Try upgrading to v17.6.0. It solved the issue for me.
In My case eslint 8.9.0 was the culprit. Rollback fixed it.
In short, Im looking for a way to capture the text content of the debug console inside a vscode extension. The following code snippet does pretty much exactly what I want only for the Terminal instead of the debug console. You can also right click in the console and select -> copy all. In the end I wont be pasting it to a new code window but pushing it to an endpoint to automate test reporting.
vscode.commands.executeCommand('workbench.action.terminal.selectAll').then(() => {
vscode.commands.executeCommand('workbench.action.terminal.copySelection').then(() => {
vscode.commands.executeCommand('workbench.action.terminal.clearSelection').then(() => {
vscode.commands.executeCommand('workbench.action.files.newUntitledFile').then(() => {
vscode.commands.executeCommand('editor.action.clipboardPasteAction');
});
});
});
});
I have tried this but I get an error in the console.log
vscode.commands.executeCommand('repl.action.copyall').then(() => {
vscode.commands.executeCommand('workbench.action.files.newUntitledFile').then(() => {
vscode.commands.executeCommand('editor.action.clipboardPasteAction');
});
});
rejected promise not handled within 1 second: Error: command 'repl.action.copyall' not found
extensionHostProcess.js:1048
stack trace: Error: command 'repl.action.copyall' not found
at u._tryExecuteCommand (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:4213:713)
at file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:4213:594
Any help pointing me in the right direction would be appreciated!
don't do callback hell with Promises
Just return a new Promise in the then() handler
vscode.commands.executeCommand('workbench.action.terminal.selectAll')
.then(() => vscode.commands.executeCommand('workbench.action.terminal.copySelection'))
.then(() => vscode.commands.executeCommand('workbench.action.terminal.clearSelection'))
.then(() => vscode.commands.executeCommand('workbench.action.files.newUntitledFile'))
.then(() => vscode.commands.executeCommand('editor.action.clipboardPasteAction'))
I am using nuxt community axios module.
And this is my plugin inside plugins/axios.js
Everything was working fine but now all of a sudden I get the error $axios.onError is not a function
Here is my plugins/axios.js
export default function({ $axios, store, redirect }) {
$axios.onError(error => {
if (error.response.status === 422) {
store.dispatch("validation/setErrors", error.response.data.errors);
return redirect("/login");
}
return Promise.reject(error);
});
$axios.onRequest(config => {
config.headers["Content-Type"] = "application/json";
config.headers["Access-Control-Allow-Origin"] = "*";
store.dispatch("validation/clearErrors");
});
}
It was a weird issue so I went back to my previous project and used the exact versions of those packages and it worked!
I had to update package.json for the following packages from this:
"#nuxtjs/auth": "^4.5.3",
"#nuxtjs/axios": "^4.5.2",
// to
"#nuxtjs/auth": "^4.5.2",
"#nuxtjs/axios": "^5.3.3",
I'm going to use the Ionic native Transfer plugin as shown below.
Problem is here this.file.dataDirectory.It shows error like [ts] Property 'dataDirectory' does not exist on type 'File'..Can you tell me what is the solution for this?
download() {
const fileTransfer: TransferObject = this.transfer.create();
const url = 'http://www.example.com/file.pdf';
fileTransfer.download(url, this.file.dataDirectory + 'file.pdf').then((entry) => {
console.log('download complete: ' + entry.toURL());
}, (error) => {
// handle error
});
}
Oh.. My bad :(
I have to install File plugin too :D
$ ionic cordova plugin add cordova-plugin-file --save
$ npm install --save #ionic-native/file
I use iron.io to call the following parse.com function to get Facebook details of my user's friends.
var getDetailsForID = function (fbID) {
var thePromise = new Parse.Promise();
// TODO: maybe we can batch several users together into a single request................
console.log("Enter getDetailsForID");
FB.api('/v1.0', 'post', {
batch: [
{ method: 'get', name: 'basic', relative_url: fbID + '?fields=id,name,gender&include_headers=false', omit_response_on_success: false },
]
}, function(res) {
console.log("Enter callback in getDetailsForID");
if(!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
return;
}
console.log(" getDetailsForID res: " + res);
thePromise.resolve(res);
});
console.log("Exit getDetailsForID");
return thePromise;
}
In the iron.io log I see:
Enter callback in getDetailsForID
[Error: 139994800940864:error:0607907F:digital envelope routines:EVP_PKEY_get1_RSA:expecting an rsa key:../deps/openssl/openssl/crypto/evp/p_lib.c:288:
The following are not called:
console.log(" getDetailsForID res: " + res);
thePromise.resolve(res);
Any idea how to resolve this problem?
Since the answer to this question, IronWorker has released a Docker workflow. Feel free to use our official iron/node Docker Image. https://github.com/iron-io/dockerworker/tree/master/node
Ahh this is definitely not a problem with Iron.io but a problem with your post to the Facebook v1.0 API call.
+ '?fields=id,name,gender&include_headers=false', omit_response_on_success: false
do you really want to omit response on success? Which Facebook endpoint are you sending a Post to?
edit
IronWorker is currently set to 0.10.25 as of 07/22/2014, Use if your node version is < 0.10.25 you may receive this error.
fix: load your own version of node
in your .worker file add the following
deb "http://ppa.launchpad.net/chris-lea/node.js/ubuntu/pool/main/n/nodejs/nodejs_0.10.29-1chl1~trusty1_amd64.deb"
# OR you can download it from a local copy
deb "nodejs_0.10.29-1chl1~trusty1_amd64.deb"
You can install other missing or updated versions of binaries in a similar manner if there is a .deb for it.
Example in practice here on github
tldr.
use latest version of node, possibly openssl also.