worldwide-asset-exchange / waxjs

Javascript API for integration with the WAX Cloud Wallet.
MIT License
126 stars 103 forks source link

Global is not defined (for the Global.fetch in eosjs-jsonrpc.js line 87) #60

Open soleanos opened 3 years ago

soleanos commented 3 years ago

Hello, im trying to implement Waxjs into an Angular app, i did an npm i @waxio/waxjs, then i imported with "import * as waxjs from "@waxio/waxjs/dist";" but when i try to call it with " const wax = new waxjs.WaxJS('https://wax.greymass.com/', undefined, undefined, false); " or new waxjs.WaxJS('https://wax.greymass.com/%27) i have the following issue :

Global is not defined (for the Global.fetch in eosjs-jsonrpc.js line 87) I searched about webpack problms but didnt found something for solve it ( tryed to manualy require global-fetch ..ect) If someone could help me pls, thanks

ruizuikeda commented 3 years ago

same here

GuiiDo commented 3 years ago

Is there any update on this? Or perhaps any work around?

GuiiDo commented 3 years ago

@soleanos I found a fix for this. Within you polyfill.ts add the following line of code: (window as any).global = window;.

This should be placed after: import 'zone.js'.

Then in your code you can call a login like this:

    async login(): Promise<void> {
        const wax = new waxjs.WaxJS({ rpcEndpoint: 'http://wax.greymass.com', userAccount: null, pubKeys: null, tryAutoLogin: false});

        const user = await wax.login();
    }
gnollio commented 2 years ago

For people using Vite + Vue: I resolved this issue by adding a global object to the window for the root view ...

<script setup>
window.global = window
</script>
darklight9811 commented 2 years ago

@gnollio you can also do this:

import { defineConfig } from 'vite'

// https://vitejs.dev/config/
export default defineConfig({
    define: {
        global: "globalThis",
    }
})