Unexpected token '?' when trying to run 'npm run dev'
Asked Answered
B

3

5

Can someone help me with this error

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 (/Users/@#@!1/!@#@!/node_modules/next/dist/lib/commands.js:10:30)
    at Object.<anonymous> (/Users/!@#!/!@#!!#/node_modules/next/dist/bin/next:141:28)
    at Module._compile (internal/modules/cjs/loader.js:999:30)

I ran npm on a mac

Boneyard answered 27/11, 2022 at 14:1 Comment(0)
D
9

This happens, perhaps, due to incompatibility between Next.js and Node.js versions. If you upgrade your Node.js version to at least v14, it will work.

Donalddonaldson answered 2/12, 2022 at 6:20 Comment(1)
I am on node.js version 18.0.0 but this doesn't seem to work. It does download 64-bit build.Barina
U
1

I had the same issue when I try to run my next.js application. When I update the node version, error was gone.

You can use nvm(node version manager) to use multiple node versions in your computer.

Hope this will help to sort out your issue.

Unscathed answered 16/8, 2023 at 3:52 Comment(0)
B
0

If you are using node with nvm, set the default node version with

nvm alias default <version>

I was facing this issue when react-native-reanimated library was using the default version of node(12) in my system instead of the version that I was using currently(18, set using [nvm use 18] command). So, I had to set the default version to 18 and restarted my laptop, and it fixed the issue.

Banshee answered 10/4 at 6:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.