-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: [ERR_STREAM_DESTROYED] Cannot call write after a stream was destroyed. #91
Comments
The To address this, ensure that your asynchronous operations, especially those involving the printer, are properly sequenced and that you're not attempting to use the printer before it's ready or after it's been closed. Wrapping your printing logic in a Promise and using async/await can help manage these operations more predictively. Here's a more reliable approach to handle printing asynchronously: const print = (text) => {
return new Promise((resolve, reject) => {
device.open(function (error) {
if (error) {
return reject(error);
}
printer
.font('a')
.align('ct')
.style('bu')
.size(1, 1)
.text(text)
.cut()
.close(() => {
resolve();
});
});
});
}; In this setup, the Additionally, verify that all libraries, especially Implementing these suggestions should help mitigate the issues you're experiencing by ensuring proper stream management and asynchronous operation handling. If the problem persists, checking for library compatibility with your Node.js version and ensuring that your asynchronous logic is correctly structured will be crucial steps in troubleshooting further. Sources
|
`Hi! I'm getting an error that seemingly came out of nowhere, as it didn't happen during my testing phase, but did happen during my production phase.
When trying to print a receipt using my below code:
`app.post('/create/order', async (req, res) => {
// we're getting an order! let's print it!
console.log("printing order with id: #" + req.body.orderId)
console.log(req.body)
let foodString = "";
let drinksString = "";
let dessertsString = "";
})
![IMG_5667](https://private-user-images.githubusercontent.com/66906782/322020331-8c60c592-3024-40eb-b9a8-bcffcb45808a.JPG?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg4NjA5MjAsIm5iZiI6MTcxODg2MDYyMCwicGF0aCI6Ii82NjkwNjc4Mi8zMjIwMjAzMzEtOGM2MGM1OTItMzAyNC00MGViLWI5YTgtYmNmZmNiNDU4MDhhLkpQRz9YLUFtei1BbGdvcml0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WUwOTM2OTE2M2RjOWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Y41Vk0TkY8UtdGGbxDr2XCGoBUqh3FYwitkFKnu_F3g)
I get the following error:
Error [ERR_STREAM_DESTROYED] Cannot call write after a stream was destroyed`See pictures below for full error:
Is there an issue with my code, is it my Node version? (v20.11.0) I can't seem to get it working.
The text was updated successfully, but these errors were encountered: