-
-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReferenceError: Buffer is not defined #143
Comments
Install this library yarn add @esbuild-plugins/node-globals-polyfill add this import to your vite.config.js and add this in your vite.config.js import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'
export default defineConfig({
// ...other config settings
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis'
},
// Enable esbuild polyfill plugins
plugins: [
NodeGlobalsPolyfillPlugin({
buffer: true
})
]
}
}
}
|
Wow rarely I find solutions that work straight away, thanks @tomatobybike ! |
Would be nicer if this library was compatible with the browser to begin with, or add a browser build defined in the |
It seems optimizeDeps isn't run on |
vite-plugin-node-polyfills should solve both dev/build problem. |
if use nuxtjs, see nuxt/nuxt#25016 |
Yes this works but when I checked the matter, it has |
did work for me in a quasar vue.js vite setup.
const { configure } = require("quasar/wrappers");
// required for the gray-matter plugin.
// https://github.com/davidmyersdev/vite-plugin-node-polyfills
const { nodePolyfills } = require("vite-plugin-node-polyfills");
module.exports = configure(function (/* ctx */) {
return {
build: {
vitePlugins: [
nodePolyfills(),
],
},
};
}); |
when i use gray-matter in vite react project, found this error:
how to fix
The text was updated successfully, but these errors were encountered: