vite icon indicating copy to clipboard operation
vite copied to clipboard

vue3+vite reports Uncaught ReferenceError: Buffer is not defined

Open LQS5858 opened this issue 5 years ago • 18 comments

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

image

LQS5858 avatar Dec 06 '21 04:12 LQS5858

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.

github-actions[bot] avatar Dec 06 '21 07:12 github-actions[bot]

buffer is not used in vue

if you need to use node global builtins for browser you need to polyfill them

Niputi avatar Dec 06 '21 07:12 Niputi

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.

Hello,The project git repository is: https://github.com/LQS5858/newmall-vue3-vite

LQS5858 avatar Dec 07 '21 10:12 LQS5858

can't access repo

Niputi avatar Dec 07 '21 10:12 Niputi

@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 image

8bu avatar Dec 07 '21 22:12 8bu

@8bu there's no link to any repository

Niputi avatar Dec 07 '21 22:12 Niputi

@Niputi sorry my bad https://github.com/8bu/vue-vite-web3

8bu avatar Dec 07 '21 22:12 8bu

I can take a look tomorrow evening. gotta sleep do you use 2 github accounts? 8bu and LQS5858?

Niputi avatar Dec 07 '21 23:12 Niputi

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

8bu avatar Dec 07 '21 23:12 8bu

@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') }, }

javastation avatar Dec 08 '21 09:12 javastation

@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

8bu avatar Dec 08 '21 10:12 8bu

@javastation thank u it worked https://unruffled-jepsen-863a3f.netlify.app/

8bu avatar Dec 08 '21 10:12 8bu

Sorry, now the warehouse has been modified to open

LQS5858 avatar Dec 10 '21 03:12 LQS5858

@8bu there's no link to any repository

Sorry, now the warehouse has been modified to open

LQS5858 avatar Dec 10 '21 03:12 LQS5858

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 avatar Dec 10 '21 03:12 LQS5858

@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

8bu avatar Dec 10 '21 03:12 8bu

LQS5858 avatar Dec 10 '21 04:12 LQS5858

@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

LQS5858 avatar Dec 10 '21 04:12 LQS5858