错误:yarn start - 错误命令“start”未找到。

54

我正在学习React,并使用私有代码库进行开发。

我在代码库的目录下运行yarn start,但是出现了错误信息:

yarn run v1.13.0
error Command "start" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

我已经安装了Node和Yarn。

关于Node:

v10.15.0
node is /usr/local/bin/node

对于yarn:

1.13.0
yarn is /usr/local/bin/yarn

我尝试重新安装node和yarn,但是仍然得到相同的错误信息。此外,我尝试通过yarn cache clean删除yarn缓存,但似乎没有用。

package.json包含以下内容:

{
  "name": "02-Manipulating-Strings",
  "version": "1.0.0",
  "author": "ssaunier",
  "license": "UNLICENSED",
  "private": true,
  "devDependencies": {
    "eslint": "^4.7.2",
    "eslint-config-airbnb-base": "^12.0.0",
    "eslint-plugin-import": "^2.7.0",
    "jest": "^21.1.0"
  },
  "scripts": {
    "test": "(eslint lib || true) && jest"
  }
}

目录结构如下:

项目目录


2
你能给我们展示一下 package.json 文件,特别是其中的 "scripts" 部分吗? - Tsvetan Ganev
2
刚刚添加了,谢谢。 - Magofoco
1
在 package.json 中没有名为 start 的脚本。 - warl0ck
30个回答

30

package.json文件的脚本中没有start命令。

"scripts": {
  "start": "some command to be run", // you need to add this line
  "test": "(eslint lib || true) && jest"
}

也许你想运行 test 命令,可以使用 npm test / yarn test 代替?


这正是我所想的,但我有两个评论。1)我打开了私有存储库的解决方案文件,解决方案的package.json与我的匹配(而且,昨天一切都正常)。2)如果我不运行yarn start,我如何运行文件夹lib中的JS文件?我尝试使用npm run,但我得到:Lifecycle scripts included in 02-Manipulating-Strings: test (eslint lib || true) && jest - Magofoco
如果我尝试运行:node lib/01_dash_insertion.js,什么也不会发生。所以我尝试安装npm install --save-dev webpack,但是我仍然无法运行任何js文件。 - Magofoco
"start": "webpack-dev-server --mode development" "start": "webpack-dev-server --mode development" - Fábio BC Souza

8

只需运行

yarn add react-scripts

1
我尝试过了,但没有起作用。问题仍然存在。 - Jamil Matheny

6

感谢用户 Tsvetan Ganev 的见解,问题已解决。

我试图运行一个不在我的脚本中的命令。具体来说,yarn start 不在文件 package.jsonscripts 部分中。 为了解决这个问题,我添加了以下行到 scripts 中:

"start": "webpack-dev-server --mode development",

请标记Tsvetan Ganev。如果它有助于解决您的问题,请将其回复为答案。 - Hemanshu Bhojak

4

您也可以尝试首先运行npm install,然后运行npm run,或者首先运行yarn,然后再运行yarn start


我尝试使用yarn和yarn start,但仍然出现以下错误。 yarn run v1.22.10 警告 package.json:没有许可证字段 错误 命令“start”未找到。 信息 请访问https://yarnpkg.com/en/docs/cli/run以获取有关此命令的文档。 - jyotisankar
尝试在package.json的“scripts”中添加“start”:“react-scripts start”。 - Magofoco

4

实际上,我因为粗心大意没有进入主项目文件夹,所以出现了这个错误。由于这个原因,它无法找到 .json 文件。


这更适合作为注释。 - cursorrux
1
请添加更多细节以扩展您的答案,例如工作代码或文档引用。 - Community
这应该在顶部。 - ronnieotieno

4

我也遇到了同样的错误信息 "start" 命令未找到。我通过以下步骤解决了该问题。

-在终端中打开您要创建应用程序的文件夹,然后输入以下命令:

  1. npm uninstall -g create-react-app
  2. npx create-react-app 文件夹名称

(这将自动安装最新的 create-react-app 版本)

-然后运行命令 yarn start 即可。


4

我遇到了这个问题。我认为最好的解决方式是这样的。

  1. npm i -g create-react-app (安装create-react-app)
  2. create-react-app my-react-app //或者任何你想要的项目名称 (创建你的React项目)
  3. cd my-react-app (切换到你的项目目录)
  4. yarn start (启动你的项目)

3

我遇到了相同的问题,提示“start command not found”。 我按照下面的指示重新创建了React应用程序。

. Go to your parent folder in cmd
. Type yarn add create-react-app
. And yarn create-react-app FolderName

安装完后,执行 "yarn start" 命令即可启动应用。

After Installing react folder


1
请检查您的package.json文件是否有“start”脚本。如果只有依赖列表,请确保在package.json文件中有以下内容。
"devDependencies": {
    "@theia/cli": "next"
  },
  "scripts": {
    "prepare": "yarn run clean && yarn build && yarn run download:plugins",
    "clean": "theia clean",
    "build": "theia build --mode development",
    "start": "theia start --plugins=local-dir:plugins",
    "download:plugins": "theia download:plugins"
  },
  "theiaPluginsDir": "plugins",
  "theiaPlugins": {
    "vscode-builtin-css": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/css-1.39.1-prel.vsix",
    "vscode-builtin-html": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/html-1.39.1-prel.vsix",
    "vscode-builtin-javascript": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/javascript-1.39.1-prel.vsix",
    "vscode-builtin-json": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/json-1.39.1-prel.vsix",
    "vscode-builtin-markdown": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/markdown-1.39.1-prel.vsix",
    "vscode-builtin-npm": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/npm-1.39.1-prel.vsix",
    "vscode-builtin-scss": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/scss-1.39.1-prel.vsix",
    "vscode-builtin-typescript": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/typescript-1.39.1-prel.vsix",
    "vscode-builtin-typescript-language-features": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/typescript-language-features-1.39.1-prel.vsix"
  }
}

否则在包含 package.json 的文件夹中运行此命令。
错误:找不到“start”命令。
yarn run theia start /home --hostname 0.0.0.0 --port 8080

Theia应该至少在端口8080上启动。

1
如果您正在使用create-react-app并遇到此错误,则很有可能未成功安装create-react-app。请按照以下说明尝试删除全局安装的create-create-app。 使用create-react-app时未提供模板

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接