Closed fabriguespe closed 1 year ago
If you get into issues with Buffer
and polyfills
check out the fix below:
npm i buffer
polyfills.js
, in the root of your project.import { Buffer } from "buffer";
window.Buffer = window.Buffer ?? Buffer;
index.js
or index.tsx
main.js
app.vue
//has to be on the first line of the file for it to work
import "./polyfills";
vue.config.js
or webpack.config.js
:const webpack = require("webpack");
module.exports = {
configureWebpack: {
plugins: [
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
],
},
transpileDependencies: true,
};
vite.config.js
:import { defineConfig } from "vite";
import { Buffer } from "buffer";
export default defineConfig({
/**/
define: {
global: {
Buffer: Buffer,
},
},
/**/
});
nuxt.config.js
:export default {
build: {
extend(config, { isClient }) {
if (isClient) {
config.node = {
Buffer: true,
};
}
},
},
};
Describe the bug
Hello,
I encountered an issue while using the
@xmtp/xmtp-js
package in a React application running in the browser. The error message isReferenceError: Buffer is not defined
.It seems that the package is trying to use Node.js's
Buffer
object, which is not available in the browser environment. This causes the application to crash.Here's the error stack trace for reference: