-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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 use web3.js throw Uncaught ReferenceError: process is not defined #3817
Comments
replace 'dragula' with the web3 dependency |
@1329778364 Could you try |
Yeah I install Buffer, but doesn't workout |
@1329778364 Could you please do me a favor and create a reproduction repo |
Hello @1329778364. Please provide a online reproduction by codesandbox or a minimal GitHub repository. Issues labeled by |
https://github.com/1329778364/vite_vue3_web3/tree/main |
use vue-cli webpack doesn't has this problem, but use vite has , the project is follow 👍 https://github.com/1329778364/vite_vue3_web3/tree/main |
I have this problem too! so vite it is not perfect, maybe I should keep to use webpack for my project. |
added to head html file <script>window.global = window;</script>
<script type="module">
import process from "process";
import { Buffer } from "buffer";
import EventEmitter from "events";
window.Buffer = Buffer;
window.process = process;
window.EventEmitter = EventEmitter;
</script> vite.config.ts import vue from '@vitejs/plugin-vue'
export default {
resolve: {
alias: {
process: "process/browser",
stream: "stream-browserify",
zlib: "browserify-zlib",
util: 'util'
}
},
plugins: [
vue(),
]
} add these dependencies |
i dont understand why to set
and vite.config.ts
together |
完美解决了我的问题,但是我还是想知道为什么这么解决 ,从而学到更多知识。 |
have created a pull request to your reproduction showing working dev and build for me |
You are so cool. |
Thanks @Niputi That works for dev mode, but not in Prod build. I also fixed it for Prod build by using browserify to include those libs here https://github.com/coddx-hq/create-web3js-app |
To solve the problem "global is not defined "
import { defineConfig, UserConfigExport, ConfigEnv } from 'vite' import vue from '@vitejs/plugin-vue' import path from 'path'; import polyfillNode from 'rollup-plugin-polyfill-node' export default defineConfig({ plugins: [ vue(), polyfillNode() ], optimizeDeps: { exclude: ['dragula'] } })
and then throw Uncaught ReferenceError: process is not defined, problem .
so How can I fix it? thanks!
The text was updated successfully, but these errors were encountered: