当前位置: 首页 > 知识库问答 >
问题:

我无法得到反应和运行。当我键入npm start时,它会给我一个错误[重复]

颜志业
2023-03-14

正如你所看到的,我得到了这个错误。和我的包裹有关。json?默认值如下所示。

{
    "name": "reactproject",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "react": "^16.12.0",
        "react-dom": "^16.12.0",
        "react-scripts": "3.3.0"
    }
}
npm ERR! missing script: start

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\k12\AppData\Roaming\npm-cache\_logs\2019-12-31T00_09_26_886Z-debug.log
PS C:\Users\k12\reactproject> ^C

在我执行命令npm rm-g create-react-app后,我在命令提示符中得到以下内容

Error: EPERM: operation not permitted, mkdir 'C:\Users\k12'
TypeError: Cannot read property 'get' of undefined
    at errorMessage (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-message.js:38:39)
    at errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:201:13)
    at C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js:78:20
    at cb (C:\Program Files\nodejs\node_modules\npm\lib\npm.js:225:22)
    at C:\Program Files\nodejs\node_modules\npm\lib\npm.js:263:24
    at C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:81:7
    at Array.forEach (<anonymous>)
    at C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:80:13
    at f (C:\Program Files\nodejs\node_modules\npm\node_modules\once\once.js:25:25)
    at afterExtras (C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:171:20)
C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:97
  var doExit = npm.config.loaded ? npm.config.get('_exit') : true
                          ^

TypeError: Cannot read property 'loaded' of undefined
    at exit (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:97:27)
    at process.errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3)
    at process.emit (events.js:210:5)
    at process._fatalException (internal/process/execution.js:150:25)
Install for [ 'create-react-app@latest' ] failed with code 7

C:\Users\k12>

共有2个答案

滕英奕
2023-03-14

查看您的package.json,您的项目似乎是一个没有模板的Create React App项目。当您的机器上有一个较旧的、全局安装的CRA时,就会发生这种情况。默认模板package.json应该如下所示:

{
  "name": "test3",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-scripts": "3.3.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

删除全局安装的版本(npm rm-g create react app),然后使用npx create react app reactproject重试

请参见https://create-react-app.dev/docs/getting-started更多信息指南。

益思博
2023-03-14

错误是因为在包中没有定义启动脚本。json

因为我不知道您的服务器设置是什么,所以我不能确切地说应该是什么。但大致是这样的:

"scripts": {
    "start": "node index.js",
}

 类似资料: