PaulBernier / factomjs

Javascript library to build applications on the Factom blockchain.
MIT License
22 stars 7 forks source link

Working in Browser but Breaking Build #13

Closed dorono closed 4 years ago

dorono commented 4 years ago

Hello Paul,

I am trying to use just the utility functions in your library for the front-end of React application, and the utilities are working great, with me importing them as follows: import {isValidPrivateAddress, isValidPrivateEcAddress, isValidPrivateFctAddress} from 'factom';

However, when I do the npm build, I get an error (something about the const keyword, I can recreate it if you like).

I guess my question is - do you have any recommendation for how to import just the utils (or the whole library if it's easier) into a front end project?

Thanks!

Doron

PaulBernier commented 4 years ago

Hello Doron,

I'm guessing it's related to some babel configuration of your project and/or the factom lib. I quickly checked MyFactomWallet code which is also a React application and uses the factom lib and found that: https://github.com/MyFactomWallet/MyFactomWallet/blob/master/src/addWallet/ImportEcForm.js#L9

On top of that if you only need the utils functions, you can import the 'factom-struct' lib instead that is lighter (contains all the utils but not all the classes to connect to a Factom node). So putting this together I'd recommend trying importing this way:

import {isValidPrivateAddress, isValidPrivateEcAddress, isValidPrivateFctAddress} from 'factom/dist/factom-struct';

I hope that solves your problem, otherwise I'd recommend diving a bit more into MyFactomWallet codebase and configuration.

dorono commented 4 years ago

@PaulBernier Importing as you have above (using 'factom/dist/factom-struct') worked(!), at least for my needs in only bringing in those 3 methods.

Thanks for the help as well as your great work on this library!

PaulBernier commented 4 years ago

Awesome, thank you!