hashgraph / hedera-sdk-js

Hedera™ Hashgraph SDK for JavaScript/TypeScript
https://docs.hedera.com/guides/docs/sdks
Apache License 2.0
277 stars 145 forks source link

Unexpected or invalid token in the require statement #880

Closed jigsnptel closed 2 years ago

jigsnptel commented 2 years ago

Description

I installed hedera-js-sdk on my machine before few months. it was working fine. suddenly it is giving error in the "require" stmt, the error is "unexpected or invalid token". I tried all the options like, installing hedera js sdk again, removed node_modules and again used npm install, created new file. nothing works. I tried "import" option also. but it gives "unexpected token {" error. pls help. I also tried "experimental modules" option. nothing works.

Steps to reproduce

const { Client } = require("@hashgraph/sdk"); require("dotenv").config();

async function main() {

//Grab your Hedera testnet account ID and private key from your .env file
const myAccountId = process.env.MY_ACCOUNT_ID;
const myPrivateKey = process.env.MY_PRIVATE_KEY;

// If we weren't able to grab it, we should throw a new error
if (myAccountId == null ||
    myPrivateKey == null ) {
    throw new Error("Environment variables myAccountId and myPrivateKey must be present");
}
const client = Client.forTestnet();

client.setOperator(myAccountId, myPrivateKey);

} main();

Additional context

C:\Program Files\nodejs\node.exe .\index.js Uncaught SyntaxError: Invalid or unexpected token Process exited with code 1 package.json file

{ "name": "hello-hedera-js-sdk", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "@hashgraph/sdk": "^2.7.0", "dotenv": "^14.2.0" } }

"C:\Users\Vipul\hello-hedera-js-sdk\index.js" file path

Hedera network

testnet

Version

v2.7.0

Operating system

Windows

jigsnptel commented 2 years ago

image screenshot after running index.js file. showing unexpected token in file nodechannel.cjs at line 92. pls help. not going further without solving this problem

SimiHunjan commented 2 years ago

Try changing the value 10_000 to 10000 and see if that works.

jigsnptel commented 2 years ago

hi, thank you, but not able to open nodechannel.js

jigsnptel commented 2 years ago

it worked, thank you very much.

SimiHunjan commented 2 years ago

glad it worked!!