Skip to content
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

vite can't use web3.js , Uncaught ReferenceError: global is not defined #3816

Closed
okevinok opened this issue Jun 15, 2021 · 5 comments
Closed

Comments

@okevinok
Copy link

when i use web3 in vite project ,

image

it can be used in vue-cli ,how can I fix it ?

@Shinigami92
Copy link
Member

This doesn't look like a feature(/enhancement) request 👀
You should open a bug issue or ask a question in the discussion section

Maybe this is also a duplicate and already resolved via #2618 (comment)

So I will close this for now and please open a bug issue if you have further problems

@Niputi
Copy link
Contributor

Niputi commented Jun 15, 2021

after you have added added the global shim to the head of your html file you will most likely see error from more node specific dependencies which you should be able to solve like this

vite.config.js

import { defineConfig } from 'vite'
import polyfillNode from 'rollup-plugin-polyfill-node'

export default defineConfig({
  plugins: [
    polyfillNode()
  ],
  optimizeDeps: {
    exclude: ['dragula'] // <- modules that needs shimming have to be excluded from dep optimization
  }
})

@okevinok
Copy link
Author

@shellscape
Copy link

Vite users: please do not ignore issue templates in other repositories.

@github-actions
Copy link

This issue has been locked since it has been closed for more than 14 days.

If you have found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Vite version. If you have any other comments you should join the chat at Vite Land or create a new discussion.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants