Skip to content
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

The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Promise #980

Open
proginter opened this issue Jan 12, 2021 · 8 comments
Labels
bug there is a bug in the way jimp behaves help wanted

Comments

@proginter
Copy link

Expected Behavior

I need it will not kill the program because of an error I dont know why is happening

Current Behavior

I get sometimes error, I dont know when, but it not on my code.

events.js:292
throw er; // Unhandled 'error' event
^
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Promise
at WriteStream.Writable.write (internal/streams/writable.js:285:13)
at WriteStream. (/home/XXX/domains/XXX.com/public_html/server/node_modules/@jimp/core/dist/index.js:589:18)
at WriteStream.emit (events.js:315:20)
at internal/fs/streams.js:380:12
at FSReqCallback.oncomplete (fs.js:171:23)
Emitted 'error' event on process instance at:
at emitUnhandledRejectionOrErr (internal/event_target.js:545:11)
at MessagePort.[nodejs.internal.kHybridDispatch] (internal/event_target.js:358:9)
at MessagePort.exports.emitMessage (internal/per_context/messageport.js:18:26) {
code: 'ERR_INVALID_ARG_TYPE'
}

Failure Information (for bugs)

An error, it happening 1 - 2 times in a day I dont know why, but I using your library to resize and compress images.

Steps to Reproduce

Screenshots

Context

  • Jimp Version: 0.13.0
  • Operating System: Centos 7 64bit
  • Node version: 14.15.4

Failure Logs

Thank you!

@marinoandrea
Copy link

I am getting the same error on version 0.16.1 and node 15.8.0 while performing Jimp.writeAsync.
The error must be inside some callback since try-catching does not help.

@agincel
Copy link

agincel commented Mar 20, 2021

I'm encountering this same issue.

@WannaBeChay
Copy link

Same issue.

@TunjiDev
Copy link

TunjiDev commented Aug 3, 2021

Same issue, how do we resolve this pls?

@WannaBeChay
Copy link

WannaBeChay commented Aug 10, 2021 via email

@flixcheck
Copy link

We're getting the same error on version 0.16.1 with several files. Since these are files of our customers which are – in the case of an error – deleted immediately due to security considerations, we cannot provide the files to reproduce the error. This is the stack trace:

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer. Received an instance of Promise
    at validChunk (_stream_writable.js:281:10)
    at WriteStream.Writable.write (_stream_writable.js:316:21)
    at WriteStream.<anonymous> (/app/node_modules/@jimp/core/dist/index.js:589:18)
    at WriteStream.emit (events.js:314:20)
    at WriteStream.EventEmitter.emit (domain.js:483:12)
    at internal/fs/streams.js:366:10
    at FSReqCallback.oncomplete (fs.js:156:23)'

@ivatov
Copy link

ivatov commented Dec 20, 2021

I encountered this when trying to read, manipulate and eventually write every image from a given collection of images . What I did to workaround it:

import { writeFile } from 'node:fs/promises';
import jimp from 'jimp';

// given `imgName` and `imgPath`:
const jimpImg = await jimp.read(imgPath);
// do whatever you like with jimpImg
const imgData = await jimpImg.getBufferAsync(jimp.AUTO);
await writeFile(imgName, imgData);

@stevezac-osu
Copy link
Contributor

Hi there. I've just added a pull request to resolve this issue. When I tested this issue, I was only able to recreate this when encoding as a GIF. Upon inspection, it looks like the GIF type encoder returns a Promise, whereas the other types return strings or buffers. This is especially difficult for the write function, which opened a stream and wrote the buffer to the stream. For GIFs, that meant the write function was trying to write a promise to the stream, which is what was throwing the error.

The commit I made should resolve the issue. Please let me know if this doesn't solve the issue for everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug there is a bug in the way jimp behaves help wanted
Projects
None yet
Development

No branches or pull requests

9 participants