You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2022/01/31 07:31:00 UTC

[jira] [Work logged] (AVRO-3322) JavaScript: Buffer is not defined in browser environment

     [ https://issues.apache.org/jira/browse/AVRO-3322?focusedWorklogId=717791&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-717791 ]

ASF GitHub Bot logged work on AVRO-3322:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 31/Jan/22 07:30
            Start Date: 31/Jan/22 07:30
    Worklog Time Spent: 10m 
      Work Description: martin-g commented on pull request #1473:
URL: https://github.com/apache/avro/pull/1473#issuecomment-1025451954


   I've created https://issues.apache.org/jira/browse/AVRO-3338 for ESM.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 717791)
    Time Spent: 3h 20m  (was: 3h 10m)

> JavaScript: Buffer is not defined in browser environment
> --------------------------------------------------------
>
>                 Key: AVRO-3322
>                 URL: https://issues.apache.org/jira/browse/AVRO-3322
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: js
>         Environment: Firefox 96 & Brave 1.34(based on chromium)
>            Reporter: ruleeeer
>            Assignee: Martin Tzvetanov Grigorov
>            Priority: Blocker
>              Labels: pull-request-available
>             Fix For: 1.11.1, 1.12.0
>
>         Attachments: image-2022-01-25-15-57-43-468.png
>
>          Time Spent: 3h 20m
>  Remaining Estimate: 0h
>
> When I use avro in my browser, I find that I get the `Buffer is undefined error`
> !image-2022-01-25-15-57-43-468.png!
> The code I use is simple, it comes from the github repository readme.md
> {code:javascript}
> var avro = require('avro-js');
> var type = avro.parse({
>   name: 'Pet',
>   type: 'record',
>   fields: [
>     {name: 'kind', type: {name: 'Kind', type: 'enum', symbols: ['CAT', 'DOG']}},
>     {name: 'name', type: 'string'}
>   ]
> });
> var pet = {kind: 'CAT', name: 'Albert'};
> var buf = type.toBuffer(pet); // Serialized object.
> var obj = type.fromBuffer(buf); // {kind: 'CAT', name: 'Albert'}
> {code}
> Later I traced the source code and found that Buffer is used directly in `/etc/browser/avro.js` and `/lib/schema.js`, which is not a problem in the node environment because the Buffer object is mounted globally, but it is a problem in the browser environment because using buffer polyfill will not mount the Buffer object globally, You need to  declare `var Buffer = require('buffer').Buffer` manually, so that it can be used in the browser environment without affecting the node environment, which also gets its Buffer from require('buffer').



--
This message was sent by Atlassian Jira
(v8.20.1#820001)