【问题标题】:Why is npm start (after create-react-app) failing to run?为什么 npm start(在 create-react-app 之后)无法运行?
【发布时间】:2019-07-03 20:13:58
【问题描述】:

使用 create-react-app 创建示例反应应用程序后,npm start 失败。

我已经尝试过使用节点 11.4 和 10.4 (npm 6.4.1)

npm install create-react-app -g
create-react-app t2
cd t2
npm start

预期

为了能够启动简单的反应服务器以在浏览器中访问 localhost:3000

实际

服务器没有启动,在我的终端里得到了这个:

$ npm start

> t2@0.1.0 start /Users/samr/dev/githubs/react/t2
> react-scripts start

/Users/samr/dev/githubs/react/t2/node_modules/ajv/lib/keyword.js:65
      throw new Error('custom keyword definition is invalid: '  + this.errorsText(validateDefinition.errors));
      ^

Error: custom keyword definition is invalid: data.errors should be boolean
    at Ajv.addKeyword (/Users/samr/dev/githubs/react/t2/node_modules/ajv/lib/keyword.js:65:13)
    at module.exports (/Users/samr/dev/githubs/react/t2/node_modules/ajv-errors/index.js:10:7)
    at Object.<anonymous> (/Users/samr/dev/githubs/react/t2/node_modules/schema-utils/src/validateOptions.js:22:1)
    at Module._compile (internal/modules/cjs/loader.js:723:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:734:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Module.require (internal/modules/cjs/loader.js:659:17)
    at require (internal/modules/cjs/helpers.js:22:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! t2@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the t2@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/samr/.npm/_logs/2019-02-09T23_19_40_848Z-debug.log

【问题讨论】:

  • 看起来像一个已知问题:github.com/webpack/webpack/issues/8768
  • 我也遇到了这个问题。对于我昨晚创建的应用程序,npm start 对我来说工作得很好,但是今天我尝试将 create-react-app 用于一个新项目,并且在新项目中 npm start 对我不起作用。从我以前的应用程序复制我的 node_modules 文件夹确实有助于作为一种临时解决方法,但是一旦我尝试将反应路由器安装到我的新应用程序中然后运行 ​​npm start,我又遇到了这个错误。
  • 这里一样,也许你可以检查这个github.com/webpack/webpack/issues/8768,更改文件 node_modules\ajv-errors\index.js 文件中的文件,正如有人说这里现在解决的那样快速修复

标签: reactjs npm create-react-app


【解决方案1】:

接受的答案对我不起作用。相反,我这样做了:

  • 已删除 node_modules 文件夹。
  • cd 到项目父目录。

    npm 安装
    npm 开始

这就像一个魅力。

【讨论】:

    【解决方案2】:

    这里提到了快速修复:

    基本上转到 node_modules/ajv/lib/keyword.js 并注释掉第 64 和 65 行。

    【讨论】:

    • 我的node_modules目录中没有ajv文件夹
    【解决方案3】:

    只需将 resolutions 添加到您的 package.json 中,如下所示:

      { 
        "dependencies": {
          ...
        }
        "resolutions": {
          "ajv": "6.8.1"
        }
      }
    

    然后运行npm install。如果你使用纱线,yarn install

    【讨论】:

    • 我添加了这个,安装了 npm,但 npm start 仍然以同样的方式失败。
    【解决方案4】:

    正如@atsnam 所说,您可以在这里找到解决方案https://github.com/webpack/webpack/issues/8768

    如果你使用纱线

    在 package.json 中添加以下内容

    "resolutions": {
      "ajv": "6.8.1"
    }
    

    然后运行yarn install

    如果你使用 npm

    npm uninstall ajv
    npm install ajv@6.8.1
    

    这对我有用

    【讨论】:

    • 如果您部署应用程序,它将无法工作。我建议将"ajv": "6.8.1" 添加到依赖项中
    • 修改为npm install --save ajv@6.8.1
    • 如果您使用的是 npm 5 或更新版本,所有安装都应默认保存到 package.json
    • 我在从 GitHub 下载的 TomTom ReactJS 示例中遇到了同样的问题。这个答案解决了这个问题。
    【解决方案5】:

    根据 Github 回答中的建议,以下更改使我能够工作。

    To fix this error, just change:
    Line 14: `errors: 'full',`
    to:
    Line 14: `errors: true`
    in file **node_modules\ajv-errors\index.js**
    

    【讨论】:

      猜你喜欢
      • 2020-09-23
      • 2019-03-18
      • 2021-01-03
      • 1970-01-01
      • 2020-11-17
      • 2021-09-26
      • 1970-01-01
      • 2020-07-11
      • 1970-01-01
      相关资源
      最近更新 更多