Search code examples
node.jsrabbitmq

Unexpected token '?' when run send.js or receive.js from rabbitMQ tutorial


I tried to learn RabbitMQ, and I follow the Streams example with NodeJS. I copied the source code of send.js and receive.js, but when i run "npm run send" or "npm run receive" it give me this error

[email protected] send node send.js

/home/italspazio-zorin/Scrivania/rabbitmq/node_modules/rabbitmq-stream-js-client/dist/client.js:43 this.connection = connection ?? this.getLocatorConnection(); ^

SyntaxError: Unexpected token '?' at wrapSafe (internal/modules/cjs/loader.js:915:16) at Module._compile (internal/modules/cjs/loader.js:963:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Module.require (internal/modules/cjs/loader.js:887:19) at require (internal/modules/cjs/helpers.js:85:18) at Object. (/home/italspazio-zorin/Scrivania/rabbitmq/node_modules/rabbitmq-stream-js-client/dist/index.js:18:14) at Module._compile (internal/modules/cjs/loader.js:999:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

I'm on Linux (Zorin OS) with rabbitmq installed and the server running, I can access to the control panel with http://localhost:15672/ address.


Solution

  • Your node version does not support coalescing operator (??)

    You need to Update to Node 16 or above

    Check your version

    node -v
    

    install nvm

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
    

    Terminal Restart

    source ~/.nvm/nvm.sh
    

    install and use node 16

    nvm install 16
    nvm use 16