Home > database >  Unexpected token Error while upgrading react in nextjs app
Unexpected token Error while upgrading react in nextjs app

Time:10-27

I want to upgrade to React 18 in nextjs app. I followed instructions in official docs.

npm install next@latest react@latest react-dom@latest

But when I try to run npm run build I get the error:

/node_modules/next/dist/build/index.js:329
                    ...pageKeys.app ?? [],
                                     ^

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)

I've tried to google this error, but there was no luck

CodePudding user response:

Current next.js (13.0.0) requires node 14.6.0 or newer:

System Requirements

  • Node.js 14.6.0 or later
  • MacOS, Windows (including WSL), and Linux are supported

The error you see is because some of the next.js code is using a nullish coalescing operator. This language construct was introduced in node 14.0.0.

  • Related