remix-run / remix

Build Better Websites. Create modern, resilient user experiences with web fundamentals.
https://remix.run
MIT License
29.4k stars 2.48k forks source link

Unexpected token '?' during npm run dev #2400

Closed YoofiBP closed 2 years ago

YoofiBP commented 2 years ago

What version of Remix are you using?

1.2.3

Steps to Reproduce

Follow steps in the Remix tutorial up until 'Loading Data' section Stop projct. Rerun project

Expected Behavior

Remix app is served on port

Actual Behavior

node_modules/@remix-run/dev/cli.js:325 appTemplate: flags.template ?? answers.appTemplate, ^

SyntaxError: Unexpected token '?'

kmturley commented 2 years ago

This error occurs when using Node < v14 Upgrade Node to v14+ to fix

johnsonsamuel commented 2 years ago

It would have been good if there was message to upgrade node to 14+ instead of Unexpected token '?'. 🙂

mcansh commented 2 years ago

It would have been good if there was message to upgrade node to 14+ instead of Unexpected token '?'. 🙂

we do, the problem is that the message wasn't visible due to the cli having the unexpected token 🙃

na2hiro commented 2 years ago

This error also happens to newcomers with npx create-remix@latest. It would be nice to show friendly error message, or mention that on the getting started page https://remix.run/docs/en/v1

jb44 commented 2 years ago

I'm on Node 16.13 and npm 8.8 and I still get this error (Mac).

npx create-remix --template remix-run/indie-stack blog-tutorial /Users/jason/.npm/_npx/82f938b29eb562d9/node_modules/@remix-run/dev/cli/run.js:68 return (process.env.npm_user_agent ?? "").split("/")[0] || "npm"; ^

SyntaxError: Unexpected token '?'

giang-pham commented 2 years ago

I hit the same error then installed Node 18 and it works now

robotparty commented 1 year ago

If you use their Gitnode remote dev environment, what you have installed locally doesn't matter. (Hint: the terminal prompt should look like this gitpod /workspace/indie-stack if you're in gitpod vs local)

But if you're running the app locally then... here's what worked for me.

When running node on a Mac that was installed via Homebrew, make sure that the node version you're running is the one you need. node --version in my case was returning v12.x

Adding a set of aliases that allows you to switch node versions easily is a good idea I found here. Switching to the compatible version fixed the issue:

alias node19='export PATH="/usr/local/opt/node@19/bin:$PATH"'
alias node18='export PATH="/usr/local/opt/node@18/bin:$PATH"'
alias node16='export PATH="/usr/local/opt/node@16/bin:$PATH"'
alias node13='export PATH="/usr/local/opt/node@13/bin:$PATH"'
alias node12='export PATH="/usr/local/opt/node@12/bin:$PATH"'

Run: node18 node --version v18.12.1 Then run the setup command: npx create-remix@latest --template remix-run/indie-stack blog-tutorial