【问题标题】:Creating a React app with 'create-react-app my-app' for the first time首次使用“create-react-app my-app”创建 React 应用
【发布时间】:2021-09-05 12:46:30
【问题描述】:

我第一次尝试在我的本地机器上创建一个 React 应用程序。我已经使用“npm i -g create-react-app”在全局范围内成功安装了“create-react-app”安装后,当我尝试使用“create-react-app”创建一个反应应用程序时,它会创建应用程序的文件夹里面只有两个文件,分别是the items within the created folder 但是终端显示这个错误:

Error: Cannot find module 'cra-template/package.json'
Require stack:
- C:\Users\East-Sound\Desktop\node_modules\react-scripts\scripts\init.js
- C:\Users\East-Sound\Desktop\contactsudacity\[eval]
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
    at Function.resolve (internal/modules/cjs/helpers.js:98:19)
    at module.exports (C:\Users\East-Sound\Desktop\node_modules\react-scripts\sc
ripts\init.js:117:13)
    at [eval]:3:14
    at Script.runInThisContext (vm.js:134:12)
    at Object.runInThisContext (vm.js:310:38)
    at internal/process/execution.js:81:19
    at [eval]-wrapper:6:22
    at evalScript (internal/process/execution.js:80:60)
    at internal/main/eval_string.js:27:3 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\East-Sound\\Desktop\\node_modules\\react-scripts\\scripts\\init.
js',
    'C:\\Users\\East-Sound\\Desktop\\contactsudacity\\[eval]'
  ]
}

Aborting installation.
  node  has failed.

Deleting generated file... package.json
Deleting generated file... yarn.lock
Done.

我该怎么办?

【问题讨论】:

  • 你安装了node.js吗?

标签: reactjs create-react-app


【解决方案1】:

我不知道您提到的创建新 React 应用程序的方法。你为什么不试试标准的方法?

您需要在您的机器上安装 Node >= 10.16 和 npm >= 5.6。要创建项目,请运行:

npx create-react-app my-app
cd my-app
npm start

来源:https://reactjs.org/docs/create-a-new-react-app.html#create-react-app

【讨论】:

  • 我有 node.js -v=14.17.6 和 npm -v=6.14.15。我尝试了标准方式,但它给了我同样的错误
猜你喜欢
  • 1970-01-01
  • 2022-10-20
  • 2021-03-27
  • 1970-01-01
  • 2021-11-27
  • 2022-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多