【发布时间】:2020-01-26 03:26:56
【问题描述】:
使用 Tesseract NPM 包。并得到以下错误:
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of null
我知道 UnhandledPromiseRejectionWarning 是一个会引发错误并且没有 .catch() 方法的承诺。这是我的代码(也使用 npm sharp 包)
function processText() {
sharp('./screenshot.png')
.extract({ left: 40, top: 585, width: 405, height: 70 })
.resize({ height: 210 })
.toFile(`./text.png`, function (err) {
worker
.recognize('./text.png')
.then(({ text }) => {
console.log(text)
worker.terminate();
})
}
我试过了:
- 将所有内容包装在 try catch 块中
- 在代码中的
.then()方法之后链接.catch()方法
这并不能解决错误。有什么建议可以消除这个错误吗?
【问题讨论】:
标签: javascript node.js error-handling