【问题标题】:cannot start a react project with yarn start无法使用 yarn start 启动反应项目
【发布时间】:2021-08-17 11:11:07
【问题描述】:

我使用 create-react-app 创建 react 应用程序,当我使用 yarn start 时发生以下错误:

这里是项目文件夹的package.json:

{
  "name": "letmeask",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "@types/jest": "^26.0.15",
    "@types/node": "^12.0.0",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "typescript": "^4.1.2",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

这是来自upath文件夹的package.json:

{
  "name": "upath",
  "description": "A proxy to `path`, replacing `\\` with `/` for all results & new methods to normalize & join keeping leading `./` and add, change, default, trim file extensions.",
  "version": "1.2.0",
  "homepage": "http://github.com/anodynos/upath/",
  "author": {
    "name": "Angelos Pikoulas",
    "email": "agelos.pikoulas@gmail.com"
  },
  "license": "MIT",
  "keywords": [
    "path",
    "unix",
    "windows",
    "extension",
    "file extension",
    "replace extension",
    "change extension",
    "trim extension",
    "add extension",
    "default extension"
  ],
  "repository": {
    "type": "git",
    "url": "git://github.com/anodynos/upath"
  },
  "bugs": {
    "url": "http://github.com/anodynos/upath/issues",
    "email": "agelos.pikoulas@gmail.com"
  },
  "main": "./build/code/upath.js",
  "types": "./upath.d.ts",
  "preferGlobal": false,
  "scripts": {
    "test": "grunt",
    "build": "grunt lib"
  },
  "directories": {
    "doc": "./doc",
    "dist": "./build"
  },
  "engines": {
    "node": ">=4",
    "yarn": "*"
  },
  "devDependencies": {
    "chai": "~4.0.2",
    "coffee-script": "1.12.6",
    "grunt": "0.4.5",
    "grunt-contrib-watch": "^1.1.0",
    "grunt-urequire": "0.7.x",
    "lodash": "^4.17.15",
    "mocha": "~3.4.2",
    "uberscore": "0.0.19",
    "underscore.string": "^3.3.5",
    "urequire": "0.7.0-beta.33",
    "urequire-ab-specrunner": "^0.2.5",
    "urequire-rc-inject-version": "^0.1.6"
  }
}

我尝试过 yarn install、yarn update、npm install、npm upgrade、vscode 重新安装,但没有任何效果。

【问题讨论】:

  • 欢迎来到 SO!你说 npm install 到目前为止还没有工作?然后由于所需的模块不存在,因此 yarn start 也无法正常工作。可以贴一下 npm install 的日志输出吗?
  • 据我所见,图像没有显示错误。请将整个图像甚至更好的整个日志添加到问题中,以便每个人都可以看到。从那里我们也许可以说出问题
  • npm install 命令没有返回任何错误,但也没有解决问题,不管有没有这个命令都会发生同样的错误
  • 那么你原来的问题有点不对劲。您说您尝试了“npm install [...],但没有任何效果”。安装很好,我们现在可以考虑下一个想法。提问时尽量准确

标签: reactjs typescript yarnpkg


【解决方案1】:

尝试删除您的yarn.lock 并再次运行yarn install。此外,不建议在使用 yarn 时运行 npm install。如果您在一个项目中混合使用两个包管理器,可能会导致问题。 如果您确实运行了 npm install 并最终创建了一个 package-lock.json,请也将其删除,并在以后为该项目坚持使用 yarn 命令。

【讨论】:

    猜你喜欢
    • 2017-09-03
    • 2022-06-30
    • 2023-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多