创建React App语法错误:意外令牌

问题描述 投票:0回答:1

我正在学习一个教程,但我无法启动create-react-app,因为它不断遇到此语法错误。我正在使用节点v8.1.4和npm v6.14.5。以下是我的代码。不知道错误是什么。

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)
javascript node.js reactjs npm
1个回答
0
投票

问题是由this function call库中的chalk引起的:

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

[根据MDN,自Node.js 8.3.0(使用...styles标志运行时为8.0.0)以来,已支持对象文字中的扩展语法(如--harmony中所使用。)。]

由于您使用的是版本8.1.4,所以有两个基本选项:

  1. 升级Node.js
  2. 使用--harmony flag运行Node.js
© www.soinside.com 2019 - 2024. All rights reserved.