Cynsar-Foundation/second.exchange

Fix production build

ishubhamk-cynsar opened this issue · 2 comments

npm run build creates a production build in dist folder. However when you try to serve the app the nostr-tools lib start to throw errors when trying to process messages from the websocket like this

Uncaught (in promise) TypeError: WC is undefined
    Ii http://localhost:8000/vendor.b9a6401c.js:11
    so http://localhost:8000/vendor.b9a6401c.js:11
    fi http://localhost:8000/vendor.b9a6401c.js:11
    cp http://localhost:8000/vendor.b9a6401c.js:11
    xEe http://localhost:8000/vendor.b9a6401c.js:11
    T http://localhost:8000/index.2a384e8e.js:1
    Ue http://localhost:8000/index.2a384e8e.js:1
    onmessage http://localhost:8000/index.2a384e8e.js:1
[vendor.b9a6401c.js:11:99182](http://localhost:8000/vendor.b9a6401c.js)
    onmessage http://localhost:8000/index.2a384e8e.js:1

This may be due to the websocket polyfill which nostr-tools utilizes to use the node websocket lib. For some reason the vite build is not creating the right polyfill to integrate this. Need to investigate it a bit.

After spending multiple days on this one we are not able to pin point which lib is ultimately causing this issue. For time being we will need to move from vite to webpack for production build.

We tried moving to webpack but the issue remain as is, we are not able to get what is causing this issue, for anyone who want to attempt this there is a working production build here https://github.com/coddx-hq/create-web3js-app . Only extra thing that we use here is the nostr tool lib which in turn uses the node crypto lib which causes this issue on the browser. Tried using crypto-browserify with no success.
Without much of an option we will move our UI workflow into the Branle client build because at least that can give us the production build.