运行 npm start 时启动脚本丢失错误

Start script missing error when running npm start

我在尝试使用 npm start 命令调试我的节点应用程序时收到此错误。

错误:
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "start"
npm ERR! node v0.12.7
npm ERR! npm  v2.11.3

npm ERR! missing script: start
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\andrmoll.NORTHAMERICA\Documents\GitHub\SVIChallenge\npm-debug.log
从调试文件:
Error: missing script: start
       at run (C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:142:19)
       at C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:58:5
       at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:345:5
       at checkBinReferences_ (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:309:45)
       at final (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:343:3)
       at then (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:113:5)
       at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:300:12
       at evalmachine.<anonymous>:334:14
       at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:102:5
       at FSReqWrap.oncomplete (evalmachine.<anonymous>:95:15)

看起来您可能没有在 package.json 文件中定义 start 脚本,或者您的项目不包含 server.js 文件。

If there is a server.js file in the root of your package, then npm will default the start command to node server.js.

https://docs.npmjs.com/misc/scripts#default-values

您可以将应用程序脚本的名称更改为 server.js 或将以下内容添加到您的 package.json

"scripts": {
    "start": "node your-script.js"
}

或者...您可以直接 运行 node your-script.js

如果您在 package.json 文件中添加第二个 "script" 密钥,也会发生此错误。如果您只在 package.json 中留下一个 "script" 键,错误就会消失。

请在 package.json

中的脚本对象中使用以下代码行
"scripts": {
    "start": "webpack-dev-server --hot"
}

对我来说,它工作得很好。

如果您正在使用 babelify 和 watchify,请转到:

package.json

并在 "scripts" 中添加:

"scripts": {
    "start": "watchify the-path-to-your-source-jsx-file -v -t [ babelify --presets [ react ] ] -o the-path-to-your-output-js-file"
}

例如:

"scripts": {
    "start": "watchify src/main.jsx -v -t [ babelify --presets [ react ] ] -o public/js/main.js"
}

感谢 DevSlopes 的标记价格

在关闭“}”之前将其添加到 package.json 文件中

,"scripts": {
  "start": "react-scripts start",
  "build": "react-scripts build",
  "test": "react-scripts test",
  "eject": "react-scripts eject"
}

确保端口已打开

var app = express();
app.set('port', (process.env.PORT || 5000));

BLAL BLA BLA 最后你有这个

app.listen(app.get('port'), function() {
    console.log("Node app is running at localhost:" + app.get('port'))
});

在 node js 中仍然是一个新手,但这导致了更多。

"scripts": {
  "prestart": "npm install",
  "start": "http-server -a localhost -p 8000 -c-1"
}

在您的 package.json 中添加此代码段,具体取决于您自己的配置。

我的已经解决了。它不是 NPM 错误,它与代理行为有关。

如果你在代理后面,

MAC
 1.  Goto System Preference (gears icon on your mac)
 2.  click your network
 3.  click advanced
 4.  click proxy
 5.  check excludes simple hostnames
 6.  add this line below (Bypass Proxy Settings...) "localhost, localhost:8080"

refer to the npm echo: "Project is running at http://localhost:8080/"

Windows
 1.  Goto your browser Proxy Settings (google it)
 2.  check Bypass local address
 3.  add this line below "localhost, localhost:8080"

检查 package.json 具有 "scripts" 属性 的文件是否存在。如果不更新脚本 属性 像这样

{
  "name": "csvjson",
  "version": "1.0.0",
  "description": "upload csv to json and insert it into MongoDB for a single colletion",
  "scripts": {
    "start": "node csvjson.js"
  },
  "dependencies": {
    "csvjson": "^4.3.4",
    "fs": "^0.0.1-security",
    "mongodb": "^2.2.31"
  },
  "devDependencies": {},
  "repository": {
    "type": "git",
    "url": "git+https://github.com/giturl.git"
  },
  "keywords": [
    "csv",
    "json",
    "mongodb",
    "nodejs",
    "collection",
    "import",
    "export"
  ],
  "author": "karthikeyan.a",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/homepage/issues"
  },
  "homepage": "https://github.com/homepage#readme"
}

应避免使用不稳定的 npm 版本。

我观察到一件事是基于 npm 版本的问题,npm 版本 4.6.1 是稳定的,但 5.x 不稳定,因为 package.json 将在创建时完美配置如果它是稳定版本,则使用默认模板,因此我们不需要手动添加该脚本。

我在 npm 5 上遇到了以下问题,所以我降级到 npm 4.6.1 然后它对我有用,


错误:尚不支持 npm 5


您似乎在使用最近发布的 npm 5。

不幸的是,Create React Native App 还不能与 npm 5 一起使用。我们 建议使用 npm 4 或 yarn,直到解决一些错误。

您可以在以下位置关注 npm 5 的已知问题: https://github.com/npm/npm/issues/16991


Devas-MacBook-Air:SampleTestApp deva$ npm start 错误!缺少脚本:开始

另一个可能的原因:当您的项目在 yarn 中初始化时,您正在使用 npm。 (我自己做的)。所以它将是 yarn start 而不是 npm start.

我有同样的问题。我尝试在 package.json 文件中编写如下代码

    "scripts": {
    "start": "<your-script-file>.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },

以我为例,如果是react项目,可以尝试升级npm,再升级react-cli

npm -g install npm@version
npm install -g create-react-app

现在不鼓励全局安装 create-react-app。而是通过执行以下操作卸载全局安装的 create-react-app 包:npm uninstall -g create-react-app(如果此命令对您不起作用,您可能必须手动删除包文件夹. 一些用户报告说他们不得不手动删除文件夹)

然后你可以运行 npx create-react-app my-app再次创建react app

参考:https://github.com/facebook/create-react-app/issues/8086

看看你的client/package.json。你必须有这些脚本

"scripts": {
  "start": "react-scripts start",
  "build": "react-scripts build",
  "test": "react-scripts test --env=jsdom",
  "eject": "react-scripts eject"
}

我在第一次安装 react-js 时遇到了这个问题: 这些行帮助我解决了问题:

npm rm -g create-react-app
npm install -g create-react-app
npx create-react-app my-app

来源:

您可能有一个旧的(全局)安装的 npm 导致了这个问题。 12月19日起,npm不支持全局安装

首先,卸载包使用:
npm uninstall -g create-react-app

一些 osx/Linux 用户可能还需要删除旧的 npm 使用:
rm -rf /usr/local/bin/create-react-app

这是目前唯一支持的生成项目的方法:
npx create-react-app my-app

终于可以运行:
npm start

尝试以下步骤:

npm rm -g create-react-app

npm install -g create-react-app

npx create-react-app my-app

绝对有效!!

根据 React 文档 https://create-react-app.dev/docs/getting-started/ 以下命令将解决此问题。

npx create-react-app my-app
cd my-app
npm start

我收到这个错误是因为我不在终端的正确目录中。

带有脚本的应用程序在文件夹 B 中。文件夹 B 在文件夹 A 中。我在 vscode 中打开文件夹 A 并在内置终端中输入“npm 运行 start”并获得错误。尝试“cd 文件夹 B”,在 ide 中打开文件夹 B,或者比我一开始更好地组织你的东西。

我刚刚偶然发现了这个问题。我重新安装了 NPM,创建了一个新的 React 应用程序(基本上是全新安装),但仍然没有成功。 终于想通了:

我的终端在正确的位置。

我不得不将目录更改到我的应用程序的更深一层。 所以我的终端在我的“projects”文件夹中,而不是我的“my-app”文件夹

路径:“/Documents/projects/my-app”

试试这个方法对你有用

我遇到了同样的问题。我试图在 VS 代码终端启动它。所以我在我的电脑终端(不是在 VS Code 里面)启动开发环境。有效。在启动之前确保你在终端中的文件中

我在第一次安装 react-js 时遇到了类似的问题:这些行帮助我解决了问题:

npm uninstall -g create-react-app
npm rm -g create-react-app
npm install -g create-react-app
npx create-react-app my-app

这对我有效。

希望它能对某人有所帮助。 如果您没有从项目的根目录打开项目,也会发生此错误。在 VS 代码中打开之前,请确保先进入该文件夹。

我在尝试 运行 "npm 运行 start"

时遇到了同样的错误

而且我的项目应该以“npm 运行 serve”启动

如果您复制一个 github 项目,您可以像这样查看项目设置:

所以一定要确保 运行 使用正确的命令,在我的例子中是

npm run serve