Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NextJS: Unexpected token '?'

I have a freshly installed Ubuntu 22.04.1 LTS on which I have installed npm and docker.

When I want to start my NextJS web server (npm run dev) and the following error message appears:


niklas@srv-code01:~/Desktop/Code/Javascript/NextJS/website_01$ npm run dev

> [email protected] dev
> next dev

/home/niklas/Desktop/Code/Javascript/NextJS/website_01/node_modules/next/dist/cli/next-dev.js:315
            showAll: args["--show-all"] ?? false,
                                         ^

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:74:18)
    at Object.dev (/home/niklas/Desktop/Code/Javascript/NextJS/website_01/node_modules/next/dist/lib/commands.js:10:30)
    at Object.<anonymous> (/home/niklas/Desktop/Code/Javascript/NextJS/website_01/node_modules/next/dist/bin/next:141:28)
    at Module._compile (internal/modules/cjs/loader.js:999:30)

I can't see anything from the error message. What is the reason for the error? The error message also occurs with the following command: npm run start

I have the latest version of NPM installed.

Start of the NPM Development or Production Server on Port 3000

like image 853
Niklas Avatar asked Jan 20 '26 22:01

Niklas


1 Answers

I had the same error and to resolve that I used the node version manager(nvm) to update my node.js version to 18.12.1.

To fix this, you need to follow the steps in this order-

  1. Run this command to get the nvm.
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

  2. Restart your terminal.

  3. Install nvm- nvm install v18.12.1

  4. Start nvm- npm run dev

You can use nvm list-remote to look at a complete list of the versions to choose from.

For more information, read here under option 3- installing-node-using-the-node-version-manager

like image 131
Solar Avatar answered Jan 22 '26 10:01

Solar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!