[
https://issues.apache.org/jira/browse/AVRO-3322?focusedWorklogId=716248&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-716248
]
ASF GitHub Bot logged work on AVRO-3322:
----------------------------------------
Author: ASF GitHub Bot
Created on: 27/Jan/22 08:15
Start Date: 27/Jan/22 08:15
Worklog Time Spent: 10m
Work Description: martin-g commented on pull request #1473:
URL: https://github.com/apache/avro/pull/1473#issuecomment-1022954166
I see!
I think the best would be to use ESM (EcmaScript modules) but I'm not sure
how hard it would be for the existing users (both Node.js and browser ones)
to migrate.
Please use your preferred bundler for the test. I'll investigate the
migration to ESM soon!
On Thu, Jan 27, 2022, 05:42 ruleeeer ***@***.***> wrote:
> @martin-g <https://github.com/martin-g>
> When upgrading from webpack4 to webpack5, the Buffer is not defined issue
> will definitely occur when using Avro-browser, because webpack4 has
> browserify built in, which will automatically convert it for you, but
> webpack5 has to declare browserify manually, like Configure it like this
>
> resolve: {
>
> fallback: {
>
> 'buffer':require.resolve('buffer')
>
> }
>
> }
>
> But that's not enough, you'll still run into the Buffer is not defined
> problem and you'll need to add a little configuration after searching
> stackoverflow or searching the webpack documentation
>
> plugins: [
>
> new webpack.ProvidePlugin({
>
> Buffer: ['buffer', 'Buffer'],
>
> }),
>
> ],
>
> This is where you'll find Avro working properly,But this is only webapck,
> there are also projects that use rollup or vite etc. to complete the
> application bundle, which will cause everyone using avro-browser to have to
> search for how to configure to solve the Buffer is not defined problem,
> also, in the official Nodejs documentation it is pointed out that although
> Buffer hangs globally, but a display declaration is a better approach.You
> can find it here https://nodejs.org/api/buffer.html#buffer,
>
> [image: image]
>
<https://user-images.githubusercontent.com/70385062/151286555-12d37205-92c4-4c79-95d3-289151911476.png>
>
> It only takes two lines to fix the above problem, doesn't it?
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/apache/avro/pull/1473#issuecomment-1022818568>, or
> unsubscribe
>
<https://github.com/notifications/unsubscribe-auth/AABYUQS4OXROJ7Q67HZTGWDUYC5JDANCNFSM5MXP7F3Q>
> .
> Triage notifications on the go with GitHub Mobile for iOS
>
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
>
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 716248)
Time Spent: 2h 20m (was: 2h 10m)
> 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
> Priority: Blocker
> Labels: pull-request-available
> Attachments: image-2022-01-25-15-57-43-468.png
>
> Time Spent: 2h 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)