jolocom / jolocom-lib

Library for interacting with the identity solution provided by Jolocom.
MIT License
24 stars 18 forks source link

ReferenceError: Can't find variable: Buffer #461

Closed dnaicker closed 3 years ago

dnaicker commented 3 years ago

Describe the bug When creating a self sovereign identity using instructions from https://jolocom-lib.readthedocs.io/en/latest/gettingStarted.html Section 1.2 inside a React Native application: `import { walletUtils } from '@jolocom/native-core' import { SoftwareKeyProvider } from '@jolocom/vaulted-key-provider'

const password = 'secretpassword'

SoftwareKeyProvider.newEmptyWallet(walletUtils, 'id:', password).then(emptyWallet => { console.log(emptyWallet) }) `

To Reproduce Steps to reproduce the behavior:

  1. Create new react-native project using expo cli: npm install -g expo-cli, expo init AwesomeProject, cd AwesomeProject
  2. Install Jolocom lib: npm install jolocom-lib --save, and optional install sdk: npm i @jolocom/sdk jolocom-lib
  3. Run npm start
  4. See error: `import { walletUtils } from '@jolocom/native-core' import { SoftwareKeyProvider } from '@jolocom/vaulted-key-provider'

const password = 'secretpassword'

SoftwareKeyProvider.newEmptyWallet(walletUtils, 'id:', password).then(emptyWallet => { console.log(emptyWallet) }) `

Expected behavior To create new empty wallet and log output to console of wallet creation.

Screenshots image

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context I am using React-Native 0.64, Node version 14.17.3, Ubuntu 20

serg-temchenko commented 3 years ago

Hello @dnaicker. It looks like the problem is in the build process it self and the way in which order the packages are loaded. Did you checked/tried the configuration in the notice on the page you are linked (under 1.1 point)?

To use the library in a browser or a react native environment additional polyfilling is required. For an example of integrating this library with a react native application, please see the Jolocom SmartWallet metro configuration.

If not - pleas check and tell if that helps... Right away I think that issue can be resolved by declaring the global Buffer variable in the file, where @jolocom/vaulted-key-provider is used. Like this:

global.Buffer = global.Buffer || require('buffer').Buffer

But it looks a bit hacky and I think there is more appropriate way to resolve this issue, will get back to this when will have some time...

dnaicker commented 3 years ago

@serg-temchenko Thank you for responding to my issue. I have used the metro file https://github.com/jolocom/smartwallet-app/blob/develop/metro.config.js in root of application folder, it resolved previous build errors.

Thank you again much appreciated.

serg-temchenko commented 3 years ago

Issue seems to be resolved.

dnaicker commented 3 years ago

@serg-temchenko Thank you soo much! I was just wondering how do I get the latest build? I did an npm update but it did not download any new update.

serg-temchenko commented 3 years ago

Hey @dnaicker Can you please provide package.json line where defined jolocom-lib dependency?

dnaicker commented 3 years ago

@serg-temchenko thanks for replying. The line is: "jolocom-lib": "^5.2.1",

image

serg-temchenko commented 3 years ago

@dnaicker thanks for the output. It looks like you have installed the latest published version from the npm registry. There are still couple of RC (release candidate) versions jolocom-lib-v5.2.2-rc2-gitpkg, jolocom-lib-v5.2.2-rc3-gitpkg, jolocom-lib-v5.3.0-rc5-gitpkg which has been released as a git tags (not published on the npm).

Despite that you still can test those versions by changing: "jolocom-lib": "^5.2.1" on "jolocom-lib": "jolocom/jolocom-lib#jolocom-lib-v5.3.0-rc5-gitpkg" to use the latest RC tag.

dnaicker commented 3 years ago

@serg-temchenko thank you Serg for providing instructions on how to update. I have created a new project with expo cli, added "jolocom-lib": "jolocom/jolocom-lib#jolocom-lib-v5.3.0-rc5-gitpkg", confirmed that I do have the correct node module

image

but i receive the buffer error again:

image

my app.js file code is:

image

my package json is: image