【问题标题】:create-react-app returns an Error: Cannot find module 'react-scripts/scripts/init.js' when executedcreate-react-app 返回错误:执行时找不到模块“react-scripts/scripts/init.js”
【发布时间】:2019-12-30 06:51:25
【问题描述】:

当我尝试使用 npm 和 yarn 创建一个 react 项目时,它显示以下错误:

我尝试重新安装 node 并确保它是最新的,并通过运行 npm install -g create-react-app@latest 来创建-react-app。我还删除了 npm 和 npm-cache 文件夹以及环境变量,但对我没有任何作用,而且我一直收到同样的错误。

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'react-scripts/scripts/init.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at [eval]:2:20
    at Script.runInThisContext (vm.js:122:20)
    at Object.runInThisContext (vm.js:329:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at evalScript (internal/bootstrap/node.js:589:27)

Aborting installation.
  node  has failed.

Deleting generated file... node_modules
Deleting generated file... package.json
Deleting generated file... yarn.lock
Deleting test/ from C:\Users\Esper\projects
Done.

我认为问题是由于操作系统问题将我的 Windows 10 恢复到以前的状态,因为在恢复它之前,当我运行 create-react-app 时它工作正常。

create-react-app --version 3.1.1

节点-v v10.16.3

npm -v 6.9.0

所以 Windows 10 教育版

【问题讨论】:

  • 您在尝试生成新项目或启动现有项目时收到错误消息?
  • 当我尝试创建一个全新的项目时
  • 你用什么命令来创建新项目? npx create-react-app your-app?
  • 是的,npx create-react-app your-app 或 create-react-app your-app 都不起作用
  • 您在重新安装之前尝试过npm uninstall create-react-app 吗?

标签: node.js reactjs npm create-react-app yarnpkg


【解决方案1】:

使用npm init 安装 package.json(按回车键直到安装完毕)
之后使用 npm i react-scripts 安装 react-scripts,
然后你可以用npx create-react-app your-app 安装react。
将目录更改为 "your-app"
再次运行npm i react-scripts,它应该可以工作了。

希望我没有错过任何一步,如果可行,请告诉我:)

【讨论】:

    【解决方案2】:

    只需在 git bash 上运行此代码:

    npm install
    npm install react-scripts
    npx create-react-app your-app-name
    

    【讨论】:

      【解决方案3】:

      也许它会帮助别人。

      使用 create-react-app 后可能会发生此错误,以防路径中有一些无效字符。

      从你的路径中删除像 &amp; 这样的字符。

      例如,改成这样:

      C:\Users\...\Documents\Section 3 Components & Start\my-app
      

      到这里:

      C:\Users\...\Documents\Section 3 Components Start\my-app
      

      【讨论】:

        猜你喜欢
        • 2021-04-02
        • 2019-02-27
        • 2019-04-26
        • 2020-07-09
        • 2019-11-19
        • 1970-01-01
        • 1970-01-01
        • 2020-07-21
        • 1970-01-01
        相关资源
        最近更新 更多