Create-Next-App (Next.js) Build Failure --> Syntax Error: Unexpected token "?"


I keep getting the same error all the time. I uninstalled node.js on my laptop and reinstalled -v16.9 then ran “create-next-app”, then pushed the code to github and then try to run the project on Cloudflare using the Next.js (static). I did not change any of the settings and still I get this same error.

Please help

NPM modules installed
10:07:17.322 Installing Hugo 0.54.0
10:07:18.023 Hugo Static Site Generator v0.54.0-B1A82C61A/extended linux/amd64 BuildDate: 2019-02-01T10:04:38Z
10:07:18.028 Started restoring cached go cache
10:07:18.049 Finished restoring cached go cache
10:07:18.211 go version go1.14.4 linux/amd64
10:07:18.228 go version go1.14.4 linux/amd64
10:07:18.231 Installing missing commands
10:07:18.231 Verify run directory
10:07:18.231 Executing user command: next build && next export
10:07:18.330 /opt/buildhome/repo/node_modules/next/dist/build/index.js:347
10:07:18.330 … ?? ,
10:07:18.330 ^
10:07:18.330 SyntaxError: Unexpected token ‘?’
10:07:18.331 at wrapSafe (internal/modules/cjs/loader.js:1054:16)
10:07:18.331 at Module._compile (internal/modules/cjs/loader.js:1102:27)
10:07:18.331 at Object.Module._extensions…js (internal/modules/cjs/loader.js:1158:10)
10:07:18.331 at Module.load (internal/modules/cjs/loader.js:986:32)
10:07:18.331 at Function.Module._load (internal/modules/cjs/loader.js:879:14)
10:07:18.332 at Module.require (internal/modules/cjs/loader.js:1026:19)
10:07:18.332 at require (internal/modules/cjs/helpers.js:72:18)
10:07:18.332 at Object. (/opt/buildhome/repo/node_modules/next/dist/cli/next-build.js:10:37)
10:07:18.332 at Module._compile (internal/modules/cjs/loader.js:1138:30)
10:07:18.332 at Object.Module._extensions…js (internal/modules/cjs/loader.js:1158:10)
10:07:18.338 Failed: build command exited with code: 1
10:07:19.297 Failed: an internal error occurred

I’ve got a spare domain I can try these steps with. Please don’t delete this post in the meantime, or if you do find a solution, or if the parameters of your question change considerably, please post back to update. :slight_smile:

I’ll wait for your response then :slight_smile:

You probably need to set a NODE_VERSION environment variable in the project to the version of Node you’re using (currently max of 17, this will be addressed soon).


Ah, good call @i40west !
I had not been able to replicate this error, and this seems like something that I did without thinking when going through the docs. When I remove this variable, I get the error.