vue3+vite reports Uncaught ReferenceError: Buffer is not defined
Describe the bug
version: "vue": "^3.2.16", "vite": "^2.6.4"
Buffer is used for data conversion in the vue3+vite project, and the running project reports Uncaught ReferenceError: Buffer is not defined
Reproduction
The project git repository is: https://github.com/LQS5858/newmall-vue3-vite
System Info
System:
OS: macOS 11.6
CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
Memory: 351.83 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.15.4 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 6.14.15 - /usr/local/bin/npm
Browsers:
Safari: 14.1.2
Used Package Manager
npm
Logs
No response

Hello @LQS5858. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.
buffer is not used in vue
if you need to use node global builtins for browser you need to polyfill them
Hello @LQS5858. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with
need reproductionwill be closed if they have no activity within 3 days.
Hello,The project git repository is: https://github.com/LQS5858/newmall-vue3-vite
can't access repo
@Niputi
can't access repo
Can you check this repo instead? I've tried to fix it by following this answer It worked well on development but not production build
Reproduce steps:
- yarn build
- yarn preview
Open http://localhost:5000/ & check the console

@8bu there's no link to any repository
@Niputi sorry my bad https://github.com/8bu/vue-vite-web3
I can take a look tomorrow evening. gotta sleep do you use 2 github accounts? 8bu and LQS5858?
I can take a look tomorrow evening. gotta sleep
do you use 2 github accounts? 8bu and LQS5858?
No I just got the same issue with @LQS5858
@Niputi sorry my bad https://github.com/8bu/vue-vite-web3
Maybe it's a problem with web3, you can try this in vite.config.ts:
resolve: {
alias: {
web3: path.resolve(__dirname, './node_modules/web3/dist/web3.min.js')
},
}
@Niputi sorry my bad https://github.com/8bu/vue-vite-web3
![]()
Maybe it's a problem with web3, you can try this in
vite.config.ts:resolve: { alias: { web3: path.resolve(__dirname, './node_modules/web3/dist/web3.min.js') }, }
hmm thank u. I totally forgot about the prebuilt version. Lemme try it
@javastation thank u it worked https://unruffled-jepsen-863a3f.netlify.app/
Sorry, now the warehouse has been modified to open
@8bu there's no link to any repository
Sorry, now the warehouse has been modified to open
I can take a look tomorrow evening. gotta sleep do you use 2 github accounts? 8bu and LQS5858?
Sorry, now the warehouse has been modified to open; Warehouse address: https://github.com/LQS5858/newmall-vue3-vite
@LQS5858 Check my config https://github.com/8bu/vue-vite-web3/blob/f17d434e3eaeda9ebce633f126645f5d8aa1cd01/vite.config.ts#L26-L34 https://github.com/8bu/vue-vite-web3/blob/f17d434e3eaeda9ebce633f126645f5d8aa1cd01/index.html#L9-L20 https://github.com/8bu/vue-vite-web3/blob/f17d434e3eaeda9ebce633f126645f5d8aa1cd01/package.json#L10-L20
@LQS5858 Check my config https://github.com/8bu/vue-vite-web3/blob/f17d434e3eaeda9ebce633f126645f5d8aa1cd01/vite.config.ts#L26-L34 https://github.com/8bu/vue-vite-web3/blob/f17d434e3eaeda9ebce633f126645f5d8aa1cd01/index.html#L9-L20 https://github.com/8bu/vue-vite-web3/blob/f17d434e3eaeda9ebce633f126645f5d8aa1cd01/package.json#L10-L20
Thank you,The error has been resolved