【问题标题】:How do I start my React App After I clone it?克隆后如何启动我的 React 应用程序?
【发布时间】:2021-03-04 06:30:01
【问题描述】:

我目前正在尝试使用 netlify 部署我的应用程序,但问题是我将我的应用程序克隆到我的新计算机中,现在我遇到了一些问题。

> todolistv2@1.0.0 start /Users/hvaandres/Documents/GitHub/TodoList_React
> npm run build

npm ERR! missing script: build

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/hvaandres/.npm/_logs/2021-03-04T06_19_54_506Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todolistv2@1.0.0 start: `npm run build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the todolistv2@1.0.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/hvaandres/.npm/_logs/2021-03-04T06_19_54_546Z-debug.log

我运行了以下命令 npm install ,但仍然遇到同样的问题。这是我的调试日志:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'deploy' ]
2 info using npm@6.14.11
3 info using node@v14.15.5
4 verbose run-script [ 'predeploy', 'deploy', 'postdeploy' ]
5 info lifecycle todolistv2@1.0.0~predeploy: todolistv2@1.0.0
6 info lifecycle todolistv2@1.0.0~deploy: todolistv2@1.0.0
7 verbose lifecycle todolistv2@1.0.0~deploy: unsafe-perm in lifecycle true
8 verbose lifecycle todolistv2@1.0.0~deploy: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/hvaandres/Documents/GitHub/TodoList_React/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
9 verbose lifecycle todolistv2@1.0.0~deploy: CWD: /Users/hvaandres/Documents/GitHub/TodoList_React
10 silly lifecycle todolistv2@1.0.0~deploy: Args: [ '-c', 'npm run build && gh-pages -d build' ]
11 silly lifecycle todolistv2@1.0.0~deploy: Returned: code: 1  signal: null
12 info lifecycle todolistv2@1.0.0~deploy: Failed to exec deploy script
13 verbose stack Error: todolistv2@1.0.0 deploy: `npm run build && gh-pages -d build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1048:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
14 verbose pkgid todolistv2@1.0.0
15 verbose cwd /Users/hvaandres/Documents/GitHub/TodoList_React
16 verbose Darwin 19.6.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "deploy"
18 verbose node v14.15.5
19 verbose npm  v6.14.11
20 error code ELIFECYCLE
21 error errno 1
22 error todolistv2@1.0.0 deploy: `npm run build && gh-pages -d build`
22 error Exit status 1
23 error Failed at the todolistv2@1.0.0 deploy script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]



我的 package.json:


{
  "name": "todolistv2",
  "version": "1.0.0",
  "description": "Todo-List",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "npm run build"
    
  },
  "keywords": [
    "react",
    "todolist_project"
  ],
  "author": "Alan A. Haro",
  "license": "ISC",
  "dependencies": {
    "react-icons": "^3.11.0"
  }
}

如果有人可以帮助我,我将不胜感激。我只是想了解更多。

【问题讨论】:

  • 错误是 npm ERR! missing script: build... 说你的 package.json 文件没有 build 脚本?您的意思是改为运行npm start 吗?您是否首先将cd 放入项目目录并安装依赖项?您能否包含有问题的包 JSON 文件?
  • 我 CD 进入我的项目,我运行 npm start 并给我同样的问题。我删除了 package-lock,json 并运行 npm install。在那之后,我又运行了一次 npm start ,我遇到了同样的问题。
  • 同样的问题,您缺少启动命令吗?我们可以看到你的 package.json 文件吗?如果它丢失了,它可能只是简单的 CRA 启动命令,即"start": "react-scripts start"
  • 准备好了,应该可以看到我的package.json了
  • 对,npm run build 将不起作用,因为您也没有 build 脚本,下面的答案引导您错误。试试我上面评论的启动脚本。我很好奇,你是从哪里克隆这个 repo 的?

标签: javascript node.js reactjs testing npm


【解决方案1】:

您的包 JSON 文件似乎缺少 startbuild 命令。重新添加它们。这些是使用 create-react-app 新建的 React 应用程序的默认值。您似乎还缺少依赖项,即 reactreact-dom

{
  "name": "todolistv2",
  "version": "1.0.0",
  "description": "Todo-List",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "react-scripts start",
    "build": "react-scripts build"
  },
  "keywords": [
    "react",
    "todolist_project"
  ],
  "author": "Alan A. Haro",
  "license": "ISC",
  "dependencies": {
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-icons": "^3.11.0",
    ... add any other missing dependencies!!
  }
}

【讨论】:

    【解决方案2】:

    步骤 1

    您的系统中需要一个节点和 Npm Click here for installing Node.js and npm

    第二步

    删除Package-lock.json文件

    第三步

    用于安装节点模块:

    运行命令npm install

    第四步

    运行命令npm start

    如果不起作用,请尝试命令

    npm 运行构建

    npm run dev

    如果还是不行就打开 package.json 文件

    然后检查

    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "start": "npm run build" // your script code is "npm run build"
      },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-06
      • 1970-01-01
      • 1970-01-01
      • 2023-02-06
      • 2012-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多