js-stellar-sdk
js-stellar-sdk copied to clipboard
Error tslib MODULE_NOT_FOUND
Describe the bug I tried to run js code but got Error: 'MODULE_NOT_FOUND' on '/node_modules/tslib/tslib'.
What version are you on? "[email protected]",
To Reproduce Steps to reproduce the behavior:
- ubuntu@t2:~/ForeginTransfers/stellar$ node CreateAccount.js
internal/modules/cjs/loader.js:463 throw e; ^ Error: Package exports for '/home/ubuntu/ForeginTransfers/stellar/node_modules/tslib' do not define a valid '.' target at resolveExportsTarget (internal/modules/cjs/loader.js:460:13) at resolveExports (internal/modules/cjs/loader.js:393:16) at Function.Module._findPath (internal/modules/cjs/loader.js:492:20) at Function.Module._resolveFilename (internal/modules/cjs/loader.js:787:27) at Function.Module._load (internal/modules/cjs/loader.js:693:27) at Module.require (internal/modules/cjs/loader.js:864:19) at require (internal/modules/cjs/helpers.js:74:18) at Object.(/home/ubuntu/ForeginTransfers/stellar/node_modules/stellar-sdk/lib/strict_send_path_call_builder.js:4:15) at Module._compile (internal/modules/cjs/loader.js:971:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1011:10) { code: 'MODULE_NOT_FOUND' }
Expected behavior
node CreateAccount.js Master Account SC5O7VZUXDJ6JBDSZ74DSERXL7W3Y5LTOAMRF7RQRL3TAGAPS7LUVG3L GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI Account1 SDAR4OLZCLEGWNM7XP35ZWS7CIAVVUB7ZEM3GBFPFWWZQ3QVI66M2DWT GDHWNFDO7DDEK2PTTFMDQL2UQZFPEVDMGFMGJYLIZDSWXECE6JMW2AOM Account2 SCRGGPPTG2XNZYSYBQPI535BTIR4P3V3E2ZRYVJXX6N6ZYABEZYJ7UBS GCB6TEFUHLWUGNCZ4IVUIYPCW2PPRJWBK6RPB4OUMRE6UFAR4OGGTQUO Account3 SAUFYWDEIEPZWVSKAFDWLKSRSJMOGG3WK5DLROH624M46DBMFX5CWF3F GBGWWWTDBRIEC4XFKFRI6HVPAHDJUV4JDVBJUDD3G5FNDAQWVW2OK3ZS ...
Additional context - Solution Change every "tslib":
var tslib_1 = require("tslib");
to direct path (in my case "/home/ubuntu/ForeginTransfers/stellar/node_modules/tslib/tslib")
var tslib_1 = require("/home/ubuntu/ForeginTransfers/stellar/node_modules/tslib/tslib");
@George2Times which node version are you using? can you reproduce this issue in a https://jsfiddle.net/ ?
Node v12.19.0 (or v13.0.1) To Reproduce
- docker run --rm -it -p "8000:8000" --name stellarstellar/quickstart --standalone
- npm install --save stellar-sdk
- node CreateAccount.js
const StellarSdk = require("stellar-sdk"); const server = new StellarSdk.Server("http://127.0.0.1:8000", { allowHttp: true, }); const passphrase = "Standalone Network ; February 2017"; const MasterKey = StellarSdk.Keypair.master(passphrase); const pair1 = StellarSdk.Keypair.fromSecret( "SAEEE4UUP3DRYTEFHNFKCVB4ZCQT2W2KPFW7FLE6VLE7QABAAZATFZFD" ); const pair2 = StellarSdk.Keypair.fromSecret( "SDSQ5MJALF7VWDFEFETPGGWJK2UEQ5HU6HJBKMT5M5YDJ3WYKMC5RC3O" ); const pair3 = StellarSdk.Keypair.fromSecret( "SB6HTLWBKVY6KOGKFZE2EKH3ZFSIYHYXJOORGKIOHSMPHBCX4SS4PU6G" ); // print all keys in console const MasterSecret = MasterKey.secret(); const MasterPublicKey = MasterKey.publicKey(); console.log("Master Account", MasterSecret, MasterPublicKey); var SecretKey1 = pair1.secret(); var PublicKey1 = pair1.publicKey(); console.log("Account1", SecretKey1, PublicKey1); var SecretKey2 = pair2.secret(); var PublicKey2 = pair2.publicKey(); console.log("Account2", SecretKey2, PublicKey2); var SecretKey3 = pair3.secret(); var PublicKey3 = pair3.publicKey(); console.log("Account3", SecretKey3, PublicKey3); (async function main() { const account = await server.loadAccount(MasterPublicKey); const fee = await server.fetchBaseFee(); const transaction = new StellarSdk.TransactionBuilder(account, { fee, networkPassphrase: passphrase, }) .addOperation( StellarSdk.Operation.createAccount({ source: MasterPublicKey, destination: PublicKey1, startingBalance: "100000", }) ) .addOperation( StellarSdk.Operation.createAccount({ source: MasterPublicKey, destination: PublicKey2, startingBalance: "100000", }) ) .addOperation( StellarSdk.Operation.createAccount({ source: MasterPublicKey, destination: PublicKey3, startingBalance: "100000", }) ) .setTimeout(30) .build(); transaction.sign(MasterKey); try { const transactionResult = await server.submitTransaction(transaction); console.log(transactionResult); } catch (err) { console.error(err); } })();
Error:
internal/modules/cjs/loader.js:463 throw e; ^ Error: Package exports for '/home/ubuntu/ForeginTransfers/stellar/node_modules/tslib' do not define a valid '.' target at resolveExportsTarget (internal/modules/cjs/loader.js:460:13) at resolveExports (internal/modules/cjs/loader.js:393:16) at Function.Module._findPath (internal/modules/cjs/loader.js:492:20) at Function.Module._resolveFilename (internal/modules/cjs/loader.js:787:27) at Function.Module._load (internal/modules/cjs/loader.js:693:27) at Module.require (internal/modules/cjs/loader.js:864:19) at require (internal/modules/cjs/helpers.js:74:18) at Object. (/home/ubuntu/ForeginTransfers/stellar/node_modules/stellar-sdk/lib/strict_send_path_call_builder.js:4:15) at Module._compile (internal/modules/cjs/loader.js:971:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1011:10) { code: 'MODULE_NOT_FOUND' }
Why it can't locate 'tslib'? But can locate '/home/ubuntu/ForeginTransfers/stellar/node_modules/tslib/tslib'? I don't how to reproduce this issue in a https://jsfiddle.net/, because I use stellarstellar/quickstart in docker.