ruleeeer commented on pull request #1473:
URL: https://github.com/apache/avro/pull/1473#issuecomment-1022818568
@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
``` javascript
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
``` javascript
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,
<img width="1517" alt="image"
src="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?
--
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]