Truffle init Syntax error: unexpected token (Rarible tutorial NR 6)

Hi, I am getting this error when trying to init truffle

C:\Users\PC\Desktop\Tokens\Rarible clone\contracts>truffle init
C:\Users\PC\AppData\Roaming\npm\node_modules\truffle\build\223.bundled.js:22182
  } catch {
          ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at Object.__webpack_require__.f.require (C:\Users\PC\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:617:28)

I tried reinstalling Truffle.

Hi Lukas,

This could be related to your node version. As a developer I’d highly recommend using Node Version Manager (nvm) as many packages have different levels of NodeJs compatibility and many do NOT support the latest version.

NVM can be installed here:

With NVM you can change the version of node running on your computer with the command line in seconds. Beware that you’ll need to re-install truffle and any other global npm packages for each installed version of node in nvm.

nvm install 12.20.2
nvm use 12.20.2

I’m currently using node 12.20.2 and this seems to work well with truffle.

$ nvm list

  * 12.20.2 (Currently using 64-bit executable)
    12.16.0
    12.14.1
    10.22.0
    10.18.0
    8.17.0
$ truffle version
Truffle v5.1.59 (core: 5.1.59)
Solidity v0.5.16 (solc-js)
Node v12.20.2
Web3.js v1.2.9

Hope that helps.

And please follow the style guide for posing code/error messages:

Wow, it did work thank you so much.

1 Like