jolocom / jolocom-lib

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

Help needed during Module import whit node.js #463

Closed MrM0nkey closed 3 years ago

MrM0nkey commented 3 years ago

Setup

What I have done

Step 1.

$mkdir ~/Jolocom_testing
$cd ~/Jolocom_testing
$npm init

Step 2. Install jolocom-lib according to https://jolocom-lib.readthedocs.io/en/latest/gettingStarted.html#how-to-install-the-jolocom-library

dockercm@dockercm-VirtualBox:~/Jolocom_testing$ npm install jolocom-lib --save
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated xmldom@0.1.19: Deprecated due to CVE-2021-21366 resolved in 0.5.0
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142

added 166 packages, and audited 167 packages in 10s

32 packages are looking for funding
  run `npm fund` for details

6 moderate severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

Step 3 Copied the code snippet from https://jolocom-lib.readthedocs.io/en/latest/gettingStarted.html#how-to-create-a-self-sovereign-identity

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)
})

I saved the code into a index.ts file on the to level of my working directroy.

Step 4 compile the type script

dockercm@dockercm-VirtualBox:~/Jolocom_testing$ tsc index.ts

This lead to index.js with the content:

"use strict";
exports.__esModule = true;
var native_core_1 = require("@jolocom/native-core");
var vaulted_key_provider_1 = require("@jolocom/vaulted-key-provider");
var password = 'secretpassword';
vaulted_key_provider_1.SoftwareKeyProvider.newEmptyWallet(native_core_1.walletUtils, 'id:', password).then(function (emptyWallet) {
    console.log(emptyWallet);
});
console.log("test");

Step 5 run the index.js with node

dockercm@dockercm-VirtualBox:~/Jolocom_testing$ node index.js
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module '@jolocom/native-core-node-17-linux-x64'
Require stack:
- /home/dockercm/Jolocom_testing/node_modules/@jolocom/native-core/js/addon.js
- /home/dockercm/Jolocom_testing/node_modules/@jolocom/native-core/js/index.js
- /home/dockercm/Jolocom_testing/index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/dockercm/Jolocom_testing/node_modules/@jolocom/native-core/js/addon.js:9:22)
    at Module._compile (node:internal/modules/cjs/loader:1095:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1147:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:999:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/dockercm/Jolocom_testing/node_modules/@jolocom/native-core/js/addon.js',
    '/home/dockercm/Jolocom_testing/node_modules/@jolocom/native-core/js/index.js',
    '/home/dockercm/Jolocom_testing/index.js'
  ]
}

Question

How can I fix this error? I have also tried to remove the node_modules directory and reinstalled the jolocom-lib but the error remains still the same. I also tried to install jolocom-lib@4.1.0 which ended with an error:

npm install jolocom-lib@4.4.1
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated xmldom@0.1.19: Deprecated due to CVE-2021-21366 resolved in 0.5.0
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated mkdirp-promise@5.0.1: This package is broken and no longer maintained. 'mkdirp' itself supports promises now, please switch to that.
npm WARN deprecated tar.gz@1.0.7: ⚠️  WARNING ⚠️ tar.gz module has been deprecated and your application is vulnerable. Please use tar module instead: https://npmjs.com/tar
npm WARN deprecated fs-promise@2.0.3: Use mz or fs-extra^3.0 with Promise Support
npm WARN deprecated truffle-hdwallet-provider@0.0.3: WARNING: This package has been renamed to @truffle/hdwallet-provider.
npm WARN deprecated ethereumjs-block@2.2.2: New package name format for new versions: @ethereumjs/block. Please update.
npm WARN deprecated uuid@2.0.1: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated ethereumjs-tx@2.1.2: New package name format for new versions: @ethereumjs/tx. Please update.
npm WARN deprecated ethereumjs-tx@1.3.7: New package name format for new versions: @ethereumjs/tx. Please update.
npm WARN deprecated ethereumjs-vm@2.6.0: New package name format for new versions: @ethereumjs/vm. Please update.
npm WARN deprecated ethereumjs-block@1.7.1: New package name format for new versions: @ethereumjs/block. Please update.
npm WARN deprecated ethereumjs-common@1.5.2: New package name format for new versions: @ethereumjs/common. Please update.
npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
npm ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command /home/dockercm/.nvm/versions/node/v17.0.1/bin/node /home/dockercm/.nvm/versions/node/v17.0.1/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/home/dockercm/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm ERR! code 1
npm ERR! npm ERR! The git reference could not be found
npm ERR! npm ERR! command git --no-replace-objects checkout 4.0
npm ERR! npm ERR! error: pathspec '4.0' did not match any file(s) known to git
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /home/dockercm/.npm/_logs/2021-11-05T13_09_58_581Z-debug.log

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/dockercm/.npm/_logs/2021-11-05T13_10_01_686Z-debug.log

I am completely lost right now please help me.

MrM0nkey commented 3 years ago

I was using the wrong node.js version. The documentation is lacking a hint to use one of the correct versions (14,12 or 10 for linux) of node.js https://jolocom-lib.readthedocs.io/en/latest/gettingStarted.html. Now I am using node 14.18.1 and the code snippets are working like a charm.