Skip to content

Windows Buffer.from v4.x: TypeError: hex is not a function#8053

@coolaj86

Description

@coolaj86
  • Version: v4.4.7, v4.2.2
  • Platform: Windows
  • Subsystem: Buffer

I've got multiple Windows users complaining (see https://github.com/Daplie/rsa-compat.js/issues/9) on various versions of v4.x that they get an error TypeError: hex is not a function with the following code:

varhex='818afc8cce82c96b750a64352940054af6a581dc50403ddc939d29bca104a8c3db21f6f58fcc6fbd3131f4ea8b795e0dcfc554f4340d847e652fa73fd00208df66ea0b6a4b6fca59970a6f27dc5365f127b34db603d8b37b84e8070983bdb846d2f2d288e33ebdbb7eba1c766ce3457f3ea72b31d9c01ec68de55989050177dc01ded42c7d9a03676704c51475d16c07e4bb4c3defe4b6b79545b265f44249d2d4fedf739f56e07588d59bc5ea7ddf53700a6b2100068ba4ab7060193289a5634e5fd42f74106e809e44c7bfc68e9eaba6fd94d828da64fe10ad138d31c6231eae0cc87cab397b2d7c59e377b4cd7132c13d91a5f3b6ac1df2e23aca2d309773';newBuffer(hex,'hex');<Buffer818afc8cce82c96b750a64352940054af6a581dc50403ddc939d29bca104a8c3db21f6f58fcc6fbd3131f4ea8b795e0dcfc5...> Buffer.from(hex, 'hex'); TypeError: hex is not a function at Function.from (native) at Function.from (native) at repl:1:8 at REPLServer.defaultEval (repl.js:262:27) at bound (domain.js:287:14) at REPLServer.runBound [as eval] (domain.js:300:12) at REPLServer.<anonymous> (repl.js:431:12) at emitOne (events.js:82:20) at REPLServer.emit (events.js:169:7) at REPLServer.Interface._onLine (readline.js:211:10)

The buffer-v6-shim polyfill won't work because Buffer.from exists and is write-only and I can't reliably detect that it doesn't work other than with try{} catch (e){}, but again, because Buffer.from is write-only, it can't be polyfilled with the fix.

No reported problems in v6 or on other OSes (yet).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions