简体   繁体   English

错误:纱线启动 - 错误命令“start”未找到

[英]Error: yarn start - error Command “start” not found

yarn run v1.22.4 error Command "start" not found. yarn run v1.22.4 error 命令“start”未找到。 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. info 访问https://yarnpkg.com/en/docs/cli/run以获取有关此命令的文档。

This error comes up after I type yarn start in command prompt... The main problem is there is no 'scripts' in package.json..我在命令提示符下键入yarn start后出现此错误...主要问题是 package.json 中没有“脚本”。

can anyone help please?有人可以帮忙吗?

Here's an example package.json from one of my reactjs projects.这是来自我的 reactjs 项目之一的示例package.json
Depending on what environment/framework you work on, you are probably looking for the scripts object as defined below.根据您使用的环境/框架,您可能正在寻找如下定义的脚本 object。

{
  "name": "bitmex-dashboard",
  "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",
    "@types/jest": "^24.0.0",
    "@types/node": "^12.0.0",
    "@types/react": "^16.9.41",
    "@types/react-dom": "^16.9.8",
    "axios": "^0.19.2",
    "bitmex-realtime-api": "^0.4.3",
    "form-data": "^3.0.0",
    "lodash": "^4.17.15",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-redux": "^7.2.0",
    "react-scripts": "3.4.1",
    "react-tradingview-widget": "^1.3.2",
    "redux": "^4.0.5",
    "redux-logger": "^3.0.6",
    "redux-saga": "^1.1.3",
    "semantic-ui-react": "^0.88.2",
    "typescript": "~3.7.2",
    "ws": "^7.3.1"
  },
  "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"
    ]
  },
  "devDependencies": {
    "@types/lodash": "^4.14.157",
    "@types/react-redux": "^7.1.9",
    "@types/redux-logger": "^3.0.8",
    "@types/socket.io-client": "^1.4.33",
    "@types/ws": "^7.2.6",
    "redux-devtools-extension": "^2.13.8"
  }
}

If you are using nodejs, you want something like this:如果你使用的是 nodejs,你需要这样的东西:

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

Here's a brief explanation on package.json下面简单介绍一下package.json

If you are creating a new react project, you may want to use create-react-app as it handles all the initial configurations and installs all the required dependencies too如果您正在创建一个新的 React 项目,您可能需要使用 create-react-app,因为它会处理所有初始配置并安装所有必需的依赖项

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

When you write some code in a .js file you execute the content of that file passing it are argument in your terminal ||当您在.js文件中编写一些代码时,您会执行该文件的内容,并将其作为终端中的参数 || shell to node command like this shell 到这样的node命令

Here I presume you have a file which is named index.js在这里,我假设您有一个名为index.js的文件

node ./index.js 

So instead of having to type this command every time you can add a script property in your package.json file so it will reference that command every time you execute in your terminal npm run start || npm start因此,不必每次都在package.json文件中添加script属性时键入此命令,因此每次在终端中执行npm run start || npm start时都会引用该命令npm run start || npm start or yarn start if you are using Yarn . npm run start || npm startyarn start如果您使用的是Yarn

This will look like this这看起来像这样

// package.json
{
   "scripts": {
       "start": "node ./index.js",
   } 
}

Generaly you specify the entry point where you application execution must start.一般来说,您指定应用程序执行必须开始的入口点。

You can learn more about package.json file here Creating a package.json file and The package.json guide You can learn more about package.json file here Creating a package.json file and The package.json guide

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM