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

Error after error in nodejs 23.4.0: [TypeError: (intermediate value).get(...).replace is not a function] #703

Closed
3 tasks done
dincerpece opened this issue Dec 14, 2024 · 3 comments
Labels

Comments

@dincerpece
Copy link

Description

After migrating from nodejs 23.3.0 to 23.4.0, I encountered an error in my code. Your fileTypeFromBuffer function gives an error and does not return a value, and naturally my code stops working there. It does not pass to "console.log(fileType)" at all, it gives an error without even getting an empty value, and the fileTypeFromBuffer function stops working! While it worked fine in Node.js 23.3.0, this problem occurred in 23.4.0.

fileTypeFromBuffer_error1
fileTypeFromBuffer_error2

Existing Issue Check

  • I have searched the existing issues and could not find any related to my problem.

ESM (ECMAScript Module) Requirement Acknowledgment

  • My project is an ESM project and my package.json contains the following entry: "type": "module".

File-Type Scope Acknowledgment

  • I understand that file-type detects binary file types and not text or other formats.
@dincerpece dincerpece added the bug label Dec 14, 2024
@Borewit
Copy link
Collaborator

Borewit commented Dec 15, 2024

I could not reproduce your issue @dincerpece:

import { readFileSync } from 'node:fs';
import { fileTypeFromBuffer } from 'file-type';
import { versions } from 'process';

console.log(`Node.js version: ${versions.node}`);

const buffer = readFileSync('sample-gif-files-sample_640x426.gif');
const result = await fileTypeFromBuffer(buffer);
console.log(JSON.stringify(result));

Outputs:

Node.js version: 23.4.0
{"ext":"gif","mime":"image/gif"}

@Borewit Borewit added the cannot reproduce The issue described cannot be reproduced label Dec 15, 2024
@Borewit
Copy link
Collaborator

Borewit commented Dec 15, 2024

I managed to reproduce the issue, use the previous code sample, parsing: fixture.cr3.

That outputs:

TypeError: (intermediate value).get(...).replace is not a function
    at FileTypeParser.parse (file:///C:/Users/Borewit/IdeaProjects/file-type/core.js:613:77)

which refers to:

const brandMajor = new Token.StringType(4, 'latin1').get(this.buffer, 8).replace('\0', ' ').trim();

@Borewit Borewit removed the cannot reproduce The issue described cannot be reproduced label Dec 15, 2024
@Borewit
Copy link
Collaborator

Borewit commented Dec 15, 2024

Looks like a bug in Node.js 23.4.0, in the TextDecoder.decode(): nodejs/node#56219

const encoding = 'latin1';
const buffer = Buffer.from('Hello!', encoding); // Initializes: <Buffer 48 65 6c 6c 6f 21>
const textDecoder = new TextDecoder(encoding);
const decodedString = textDecoder.decode(buffer);
const returnType = typeof decodedString;
if (returnType === 'string') {
    console.log('Fine, we got a string, as expected');
} else {
    console.error('This is odd, we received an ' + returnType);
}

Outputs in 23.4.0:

This is odd, we received an object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants