【问题标题】:create-react-app: template not provided using create-react-app error/start script missing (even after removing globally installed create-react-app)create-react-app:没有使用 create-react-app 错误/启动脚本提供的模板(即使在删除全局安装的 create-react-app 之后)
【发布时间】:2020-04-11 11:36:50
【问题描述】:

我正在尝试在我的项目中安装 create-react-app,但生成了一个没有启动脚本的 package.json,并且我收到错误“未提供模板。这可能是因为您使用的是过时的创建反应应用程序的版本。 请注意,不再支持 create-react-app 的全局安装。”正如其他有关此问题的问题中所建议的,这是我已经尝试过的: npm uninstall -g create-react-appwhich create-react-app,然后是rm -rf [the path that was listed](现在当我输入which create-react-app它说which: no create-react-app in .....,然后重新启动我的电脑。

我不知道还能尝试什么。任何帮助表示赞赏。

这是我的完整错误消息/尝试运行 create-react-app 时得到的信息:

$ npx create-react-app client

Creating a new React app in C:\Users\deja\Desktop\repos\devconnect\client.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...

yarn add v1.17.3
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "win32" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@2.1.2: The platform "win32" is incompatible with this module.
info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 154 new dependencies.
info Direct dependencies
├─ react-dom@16.12.0
├─ react-scripts@3.3.0
└─ react@16.12.0
info All dependencies
├─ @babel/helpers@7.7.4
├─ @babel/plugin-proposal-async-generator-functions@7.7.4
├─ @babel/plugin-proposal-class-properties@7.7.4
├─ @babel/plugin-proposal-decorators@7.7.4
├─ @babel/plugin-proposal-dynamic-import@7.7.4
├─ @babel/plugin-proposal-json-strings@7.7.4
├─ @babel/plugin-proposal-nullish-coalescing-operator@7.7.4
├─ @babel/plugin-proposal-numeric-separator@7.7.4
├─ @babel/plugin-proposal-object-rest-spread@7.7.4
├─ @babel/plugin-proposal-optional-catch-binding@7.7.4
├─ @babel/plugin-proposal-optional-chaining@7.7.4
├─ @babel/plugin-proposal-unicode-property-regex@7.7.4
├─ @babel/plugin-syntax-decorators@7.7.4
├─ @babel/plugin-syntax-flow@7.7.4
├─ @babel/plugin-syntax-nullish-coalescing-operator@7.7.4
├─ @babel/plugin-syntax-numeric-separator@7.7.4
├─ @babel/plugin-syntax-optional-chaining@7.7.4
├─ @babel/plugin-syntax-top-level-await@7.7.4
├─ @babel/plugin-syntax-typescript@7.7.4
├─ @babel/plugin-transform-arrow-functions@7.7.4
├─ @babel/plugin-transform-async-to-generator@7.7.4
├─ @babel/plugin-transform-block-scoped-functions@7.7.4
├─ @babel/plugin-transform-block-scoping@7.7.4
├─ @babel/plugin-transform-classes@7.7.4
├─ @babel/plugin-transform-computed-properties@7.7.4
├─ @babel/plugin-transform-destructuring@7.7.4
├─ @babel/plugin-transform-dotall-regex@7.7.4
├─ @babel/plugin-transform-duplicate-keys@7.7.4
├─ @babel/plugin-transform-exponentiation-operator@7.7.4
├─ @babel/plugin-transform-flow-strip-types@7.7.4
├─ @babel/plugin-transform-for-of@7.7.4
├─ @babel/plugin-transform-function-name@7.7.4
├─ @babel/plugin-transform-literals@7.7.4
├─ @babel/plugin-transform-member-expression-literals@7.7.4
├─ @babel/plugin-transform-modules-amd@7.7.5
├─ @babel/plugin-transform-modules-commonjs@7.7.5
├─ @babel/plugin-transform-modules-systemjs@7.7.4
├─ @babel/plugin-transform-modules-umd@7.7.4
├─ @babel/plugin-transform-named-capturing-groups-regex@7.7.4
├─ @babel/plugin-transform-new-target@7.7.4
├─ @babel/plugin-transform-object-super@7.7.4
├─ @babel/plugin-transform-parameters@7.7.4
├─ @babel/plugin-transform-property-literals@7.7.4
├─ @babel/plugin-transform-react-display-name@7.7.4
├─ @babel/plugin-transform-react-jsx-self@7.7.4
├─ @babel/plugin-transform-react-jsx-source@7.7.4
├─ @babel/plugin-transform-react-jsx@7.7.4
├─ @babel/plugin-transform-regenerator@7.7.5
├─ @babel/plugin-transform-reserved-words@7.7.4
├─ @babel/plugin-transform-runtime@7.7.4
├─ @babel/plugin-transform-shorthand-properties@7.7.4
├─ @babel/plugin-transform-spread@7.7.4
├─ @babel/plugin-transform-sticky-regex@7.7.4
├─ @babel/plugin-transform-template-literals@7.7.4
├─ @babel/plugin-transform-typeof-symbol@7.7.4
├─ @babel/plugin-transform-typescript@7.7.4
├─ @babel/plugin-transform-unicode-regex@7.7.4
├─ @babel/preset-env@7.7.4
├─ @babel/preset-react@7.7.4
├─ @babel/preset-typescript@7.7.4
├─ @csstools/normalize.css@10.1.0
├─ @svgr/babel-plugin-svg-dynamic-title@4.3.3
├─ @svgr/babel-preset@4.3.3
├─ @svgr/core@4.3.3
├─ @svgr/webpack@4.3.3
├─ @types/events@3.0.0
├─ @types/glob@7.1.1
├─ @types/minimatch@3.0.3
├─ @types/node@12.12.21
├─ @types/parse-json@4.0.0
├─ @typescript-eslint/eslint-plugin@2.12.0
├─ @typescript-eslint/parser@2.12.0
├─ aggregate-error@3.0.1
├─ async@2.6.3
├─ babel-plugin-macros@2.7.1
├─ babel-plugin-named-asset-import@0.3.5
├─ babel-preset-react-app@9.1.0
├─ cacache@13.0.1
├─ clean-stack@2.2.0
├─ compression@1.7.4
├─ confusing-browser-globals@1.0.9
├─ connect-history-api-fallback@1.6.0
├─ core-js@3.5.0
├─ css-loader@3.2.0
├─ del@4.1.1
├─ dotenv@8.2.0
├─ electron-to-chromium@1.3.322
├─ eslint-config-react-app@5.1.0
├─ eslint-loader@3.0.2
├─ eslint-plugin-react@7.16.0
├─ eslint@6.7.2
├─ espree@6.1.2
├─ express@4.17.1
├─ file-loader@4.3.0
├─ fork-ts-checker-webpack-plugin@3.1.0
├─ html-entities@1.2.1
├─ http-proxy-middleware@0.19.1
├─ indent-string@4.0.0
├─ internal-ip@4.3.0
├─ is-absolute-url@3.0.3
├─ is-path-cwd@2.2.0
├─ is-path-in-cwd@2.1.0
├─ is-path-inside@2.1.0
├─ jest-watch-typeahead@0.4.2
├─ killable@1.0.1
├─ lines-and-columns@1.1.6
├─ loglevel@1.6.6
├─ minipass-collect@1.0.2
├─ minipass-flush@1.0.5
├─ minipass-pipeline@1.2.2
├─ minipass@3.1.1
├─ node-forge@0.9.0
├─ node-releases@1.1.43
├─ open@7.0.0
├─ opn@5.5.0
├─ optionator@0.8.3
├─ p-map@2.1.0
├─ p-retry@3.0.1
├─ path-is-inside@1.0.2
├─ portfinder@1.0.25
├─ postcss-modules-local-by-default@3.0.2
├─ postcss-modules-values@3.0.0
├─ postcss-normalize@8.0.1
├─ promise@8.0.3
├─ raf@3.4.1
├─ react-app-polyfill@1.0.5
├─ react-dev-utils@10.0.0
├─ react-dom@16.12.0
├─ react-error-overlay@6.0.4
├─ react-scripts@3.3.0
├─ react@16.12.0
├─ resolve-url-loader@3.1.1
├─ retry@0.12.0
├─ sanitize.css@10.0.0
├─ sass-loader@8.0.0
├─ scheduler@0.18.0
├─ selfsigned@1.10.7
├─ serialize-javascript@2.1.2
├─ serve-index@1.9.1
├─ shell-quote@1.7.2
├─ sockjs-client@1.4.0
├─ spdy@4.0.1
├─ ssri@7.1.0
├─ terser-webpack-plugin@2.2.1
├─ terser@4.4.3
├─ ts-pnp@1.1.5
├─ url-loader@2.3.0
├─ webpack-dev-middleware@3.7.2
├─ webpack-dev-server@3.9.0
├─ webpack-manifest-plugin@2.2.0
├─ webpack@4.41.2
├─ whatwg-fetch@3.0.0
├─ word-wrap@1.2.3
└─ yaml@1.7.2
Done in 86.09s.

A template was not provided. This is likely because you're using an outdated version of create-react-app.
Please note that global installs of create-react-app are no longer supported.

【问题讨论】:

    标签: reactjs create-react-app


    【解决方案1】:

    所以最好的办法是使用npm uninstall create-react-app -gyarn global remove create-react-app 全局删除create-react-app,因为这可能是您看到此错误消息的原因:

    This is likely because you're using an outdated version of create-react-app. Please note that global installs of create-react-app are no longer supported.

    一旦你删除它,请注意你不需要全局安装create-react-app来初始化一个新项目,它建议你使用至少node 5.2及以上附带的npx包运行工具.所以npx 基本上允许你在不安装它的情况下运行一个包,所以在你的情况下create-react-app

    所以要创建一个新项目,只需输入:npx create-react-app myapp,这将初始化您的 react 应用程序。

    【讨论】:

    • 正如我在问题中提到的,我已经尝试过npm uninstall create-react-app -g,但这并没有解决错误。我也在使用npx 来运行create-react-app
    • 查看与您的问题 stackoverflow.com/a/59189242/7744772 类似的答案。如果您使用纱线,请确保您使用 yarn global remove create-react-app
    • yarn global remove create-react-app 解决了这个问题,谢谢!
    【解决方案2】:

    发生这种情况的原因是您在重新启动计算机后运行了npm update -g create-react-app。再次卸载然后使用npx create-react-app name-of-my-app再次创建应用程序

    【讨论】:

    • 我只尝试了npm update -g create-react-app,因为我在尝试npm uninstall -g create-react-app, which create-react-app then rm -rf [the path that was listed] 并重新启动后遇到了同样的错误。我刚刚尝试再次进行全局卸载,但仍然遇到同样的错误。
    • 在这种情况下,如果我是你,我会重新安装 node.js
    • 使用 .msi Windows 文件重新安装节点不起作用。这就是解决问题的方法:yarn global remove create-react-app
    【解决方案3】:

    我认为@Cozy 是对的。我遇到了同样的问题。但我无法通过运行卸载我的 create-react-app 命令

    npm uninstall create-react-app -g
    

    我所做的是运行这个命令来删除 create-react-app

    which create-react-app | xargs rm
    

    然后使用npx新建一个项目

    npx create-react-app new-app
    

    希望对你有帮助:)

    【讨论】:

      【解决方案4】:

      如果您熟悉旧的 create-react-app,请试试这个。

      首先,打开 cmd 并输入:
      npm uninstall -g create-react-app
      在 C: 驱动器中创建文件夹 env。然后,在其中创建一个 bin 文件夹。
      现在添加一个名为 create-react-app.bat 的文件。
      使用记事本对其进行编辑,然后将其复制并粘贴到其中。

      npm init react-app
      

      保存它。
      现在,右键单击此 PC 或我的电脑,然后单击属性。
      现在单击高级系统设置。
      单击环境变量。
      在系统变量中,查找路径。
      现在点击编辑。
      出现新的对话框后,点击添加。
      现在粘贴:
      C:\env\bin
      现在 create-react-app 应该可以工作了。

      【讨论】:

        【解决方案5】:

        我通过以下两个步骤解决了这个问题:

        在终端输入以下命令行

        1. rm -rf /usr/local/bin/create-react-app.

        这将手动删除 create-react-app。

        现在开始创建新应用

        1. npx create-react-app my-app

        【讨论】:

          【解决方案6】:

          我会通过这个命令全局卸载 create-react-app:

          npm uninstall -g create-react-app
          
          

          npm install create-react-app@latest

          npx create-react-app my-app
          

          npx create-react-app my-app --template typescript

          删除删除我的用户根节点模块

          npx --ignore-existing create-react-app
          
          

          最后, 我在 /usr/local/bin 中找到了该文件夹,并删除了 create-react-app 文件, 并且成功了。

          【讨论】:

            猜你喜欢
            • 2021-03-16
            • 2020-03-29
            • 1970-01-01
            • 2018-10-04
            • 2022-01-17
            • 2020-04-18
            • 1970-01-01
            相关资源
            最近更新 更多