ts-sdk icon indicating copy to clipboard operation
ts-sdk copied to clipboard

[BUG] ReferenceError: exports is not defined

Open tngdomingo opened this issue 1 year ago • 1 comments

Bug Description

I wanted to sign a transaction directly on postman. It seems it should be possible to dynamically load a library as shown below but it is not working

Steps to Reproduce

  1. In postman create a dummy request with the following Pre-request script pm.sendRequest("https://unpkg.com/@bsv/sdk", (err, res) => { //convert the response to text and save it as an environment variable pm.collectionVariables.set("bsv", res.text());

    // eval will evaluate the JavaScript code and initialize the min.js eval(pm.collectionVariables.get("bsv"));

//use the library to sign a transaction and broadcast it via ARC })

  1. Send

Expected Behavior

Library is loaded and you can use it to sign, broadcast via ARC, etc.

Actual Behavior

Reference error: exports is not defined

Stack Traces or Screenshots

image

Environment

  • OS: Windows
  • Node version: n/a
  • @bsv/sdk version: 1.0.18

Additional Information

Not sure if this is actually a bug as this is a very specific use case

tngdomingo avatar Apr 23 '24 15:04 tngdomingo

More an environment incompatibility. Definitely worth investigating how to use the library in such an environment.

sirdeggen avatar May 09 '24 15:05 sirdeggen

@domingotaal you should be able to access the TS SDK modules from the unpkg cdn in a non-standard environment, such as Postman, once the above PR is merged and published to npmjs.

BraydenLangley avatar Oct 23 '24 23:10 BraydenLangley

Currently the main entry point is set to commonJS, so you'll have to reference this bundled JS file: https://unpkg.com/@bsv/[email protected]/dist/umd/bundle.js

Tested creating an instance of the PrivateKey class with a throwaway hex private key: Screenshot 2024-10-23 at 17 12 17

BraydenLangley avatar Oct 24 '24 00:10 BraydenLangley