Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create React App SyntaxError: Unexpected Token

I am following a tutorial and I cannot get create-react-app to start because it keeps running into this syntax error. I am using node v8.1.4 and npm v6.14.5. The following is my code. Not sure what the error is.

yeryndo@Yeryn:/mnt/c/Users/yeryn/desktop/Exercise Files/ch02/02_02/start$ create-react-app react-is-fun
/usr/local/lib/node_modules/create-react-app/node_modules/chalk/source/index.js:103
        ...styles,
        ^^^

SyntaxError: Unexpected token ...
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:533:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/create-react-app/createReactApp.js:37:15)
like image 772
Rina Avatar asked Jun 17 '26 13:06

Rina


1 Answers

The problem is caused by this function call in the chalk library:

const proto = Object.defineProperties(() => {}, {
    ...styles,
    level: {
         // omitted
    }
}

According to MDN, spread syntax in object literals (as used in ...styles) has been supported since Node.js 8.3.0 (8.0.0 when running with the --harmony flag).

Since you're using version 8.1.4, you have two basic options:

  1. Upgrade Node.js
  2. Run Node.js with the --harmony flag
like image 89
Robby Cornelissen Avatar answered Jun 19 '26 01:06

Robby Cornelissen



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!