GauravRatnawat
GauravRatnawat

Reputation: 859

npx hardhat compile Unexpected token?

Was following this article ran the command

npm install --dev hardhat @nomicfoundation/hardhat-toolbox

got the successful response. However when I try to run the

npx hardhat

getting Unexpected token ? response.

Tried removing the package-local.json. Also tried removing the global installation. Nothing worked.

Upvotes: 5

Views: 9583

Answers (3)

Faisal Hussain
Faisal Hussain

Reputation: 1

I also got the same error when I was installing the hardhat:

let taskName = parsedTaskName ?? task_names_1.TASK_HELP;

SyntaxError: Unexpected token '?'

try this command on your terminal

nvm use 18
nvm install 18

basically above commands will increase your node.js and npm version

then try to install

npx hardhat

Upvotes: 0

thequantumdomain
thequantumdomain

Reputation: 39

I have had a similar issue attempting to install hardhat via npx hardhat.

I found the solution from user I Like resolved this. Make sure you are using correct version of node. try nvm use 18

nvm install 18 
npx hardhat 

and had success!

Upvotes: 3

Narendranath Reddy
Narendranath Reddy

Reputation: 4133

I also got the same error!

  ~ npx hardhat Unexpected token '?'

After i upgrade my nodejs version to v16.17.0 and npm version to 8.15.0, error is gone

Once the reported error is gone then you should see the below message

āžœ  ~ npx hardhat
888    888                      888 888               888
888    888                      888 888               888
888    888                      888 888               888
8888888888  8888b.  888d888 .d88888 88888b.   8888b.  888888
888    888     "88b 888P"  d88" 888 888 "88b     "88b 888
888    888 .d888888 888    888  888 888  888 .d888888 888
888    888 888  888 888    Y88b 888 888  888 888  888 Y88b.
888    888 "Y888888 888     "Y88888 888  888 "Y888888  "Y888

šŸ‘· Welcome to Hardhat v2.11.2 šŸ‘·ā€

Upvotes: 6

Related Questions