typeerror in node version 4 and lower verison #1150

Closed
opened 2018-06-21 04:07:05 +00:00 by gabyidong · 5 comments
gabyidong commented 2018-06-21 04:07:05 +00:00 (Migrated from github.com)
if(utf8read(corpus) == utf8readb(corpus)) utf8read = utf8readb;
var utf8readc = function utf8readc(data) { return Buffer.from(data, 'binary').toString('utf8'); };
if(utf8read(corpus) == utf8readc(corpus)) utf8read = utf8readc;
Buffer.from(data, 'binary') 
TypeError: binary is not a function
    at Function.from (native)
    at Function.from (native)
    at repl:1:8
    at REPLServer.defaultEval (repl.js:252:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:417:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:211:10)
``` if(utf8read(corpus) == utf8readb(corpus)) utf8read = utf8readb; var utf8readc = function utf8readc(data) { return Buffer.from(data, 'binary').toString('utf8'); }; if(utf8read(corpus) == utf8readc(corpus)) utf8read = utf8readc; ``` ``` Buffer.from(data, 'binary') TypeError: binary is not a function at Function.from (native) at Function.from (native) at repl:1:8 at REPLServer.defaultEval (repl.js:252:27) at bound (domain.js:287:14) at REPLServer.runBound [as eval] (domain.js:300:12) at REPLServer.<anonymous> (repl.js:417:12) at emitOne (events.js:82:20) at REPLServer.emit (events.js:169:7) at REPLServer.Interface._onLine (readline.js:211:10) ```
SheetJSDev commented 2018-06-21 04:11:44 +00:00 (Migrated from github.com)

What node version are you using? According to the last test run https://travis-ci.org/SheetJS/js-xlsx/builds/386754693 this worked in 0.8.x, 0.10.x, 0.12.x and 4.x (there's also a test run for each major version 5-10)

What node version are you using? According to the last test run https://travis-ci.org/SheetJS/js-xlsx/builds/386754693 this worked in 0.8.x, 0.10.x, 0.12.x and 4.x (there's also a test run for each major version 5-10)
gabyidong commented 2018-06-21 04:13:18 +00:00 (Migrated from github.com)

@SheetJSDev ,my node version is 4.4.3

@SheetJSDev ,my node version is 4.4.3
SheetJSDev commented 2018-06-21 04:20:52 +00:00 (Migrated from github.com)

So I can reproduce in node 4.0.0-4.4.7, but it seems to have been fixed in 4.5.0.

The NodeJS CHANGELOG https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V4.md#4.5.0 suggests that the PR https://github.com/nodejs/node/pull/7562 fixed the problem in between versions.

We had to make the shift to Buffer.from (used to be new Buffer) because node 10 decided to add a deprecation warning :( .

This issue does not affect 0.12.x because the code falls back on a Buffer.from shim. It also does not affect the 6.x or 8.x or 10.x series.

Are you able to upgrade to 4.5.0+ or should we add a version check?

So I can reproduce in node 4.0.0-4.4.7, but it seems to have been fixed in 4.5.0. The NodeJS CHANGELOG https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V4.md#4.5.0 suggests that the PR https://github.com/nodejs/node/pull/7562 fixed the problem in between versions. We had to make the shift to `Buffer.from` (used to be `new Buffer`) because node 10 decided to add a deprecation warning :( . This issue does not affect 0.12.x because the code falls back on a `Buffer.from` shim. It also does not affect the 6.x or 8.x or 10.x series. Are you able to upgrade to 4.5.0+ or should we add a version check?
gabyidong commented 2018-06-21 04:29:46 +00:00 (Migrated from github.com)

@SheetJSDev ,thanks ,but i can't decide the version on the production environment. let me think it

@SheetJSDev ,thanks ,but i can't decide the version on the production environment. let me think it
SheetJSDev commented 2018-07-08 17:52:09 +00:00 (Migrated from github.com)

We're slowly updating the related projects @gabyidong .

Summary: Buffer.from had a different interface in node versions 4.0.x - 4.4.x. Unfortunately Buffer.from is non-writable, so we can't just assign to it like we can in 0.12 and lower.

In the dependencies, we've fixed this by making a separate Buffer_from variable, and we will be doing the same here

We're slowly updating the related projects @gabyidong . Summary: `Buffer.from` had a different interface in node versions `4.0.x` - `4.4.x`. Unfortunately `Buffer.from` is non-writable, so we can't just assign to it like we can in `0.12` and lower. [In the dependencies](https://github.com/SheetJS/js-codepage/blob/master/cputils.flow.js#L50), we've fixed this by making a separate `Buffer_from` variable, and we will be doing the same here
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#1150
No description provided.