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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31976722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 07:27:30  来源:igfitidea点击:

Start script missing error when running npm start

javascriptnode.jsexpresspackage.jsonnpm-scripts

提问by Andrew Moll

I'm receiving this error when trying to debug my node application using the npm start command.

尝试使用 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/issuesnpm ERR! Please include the following file with any support request: npm ERR! C:\Users\andrmoll.NORTHAMERICA\Documents\GitHub\SVIChallenge\npm-debug.log

npm 错误!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!节点 v0.12.7 npm ERR!npm v2.11.3

npm 错误!缺少脚本:启动 npm ERR!npm 错误!如果您需要帮助,您可以在以下位置报告此错误:npm ERR! https://github.com/npm/npm/issuesnpm ERR!请在任何支持请求中包含以下文件:npm ERR!C:\Users\andrmoll.NORTHAMERICA\Documents\GitHub\SVIChallenge\npm-debug.log

从调试文件:

verbose stack Error: missing script: start

4 verbose stack at run (C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:142:19)

4 verbose stack at C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:58:5

4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:345:5

4 verbose stack at checkBinReferences_ (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:309:45)

4 verbose stack at final (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:343:3)

4 verbose stack at then (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:113:5)

4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:300:12

4 verbose stack at evalmachine.:334:14

4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:102:5

4 verbose stack at FSReqWrap.oncomplete (evalmachine.:95:15)

详细堆栈错误:缺少脚本:开始

4 运行时的详细堆栈 (C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:142:19)

4 详细堆栈位于 C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:58:5

4 详细堆栈在 C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:345:5

4 在 checkBinReferences_ (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:309:45) 的详细堆栈

4 最终详细堆栈 (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:343:3)

4 详细堆栈 (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:113:5)

4 详细堆栈在 C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:300:12

evalmachine 上的 4 详细堆栈。:334:14

4 详细堆栈在 C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:102:5

4 FSReqWrap.oncomplete 上的详细堆栈 (evalmachine.:95:15)

回答by Robbie

It looks like you might not have defined a startscript in your package.jsonfile or your project does not contain a server.jsfile.

看起来您可能没有startpackage.json文件中定义脚本,或者您的项目不包含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.

如果你的包的根目录中有一个 server.js 文件,那么 npm 会将启动命令默认为 node server.js。

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

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

You could either change the name of your application script to server.jsor add the following to your package.json

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

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

Or ... you could just run node your-script.jsdirectly

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

回答by Plamen Petkov

This error also happens if you added a second "script" key in the package.json file. If you just leave one "script" key in the package.json the error disappears.

如果您在 package.json 文件中添加了第二个“脚本”键,也会发生此错误。如果您只在 package.json 中留下一个“脚本”键,错误就会消失。

回答by Дмитрий Дорогонов

In my case, it wasn't working because I used "scripts"twice. After combining - it is ok.

就我而言,它不起作用,因为我使用了"scripts"两次。组合后 - 没关系。

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

回答by Ray

Please use the below line of code in script object which is there in package.json

请在 package.json 中的脚本对象中使用以下代码行

"scripts": {
    "start": "webpack-dev-server --hot"
}

For me it worked perfectly fine.

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

回答by drjorgepolanco

If you are using babelify and watchify, go to:

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

package.json

包.json

and add this in "scripts":

并将其添加到“脚本”中:

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

An example would be:

一个例子是:

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

Thanks to Mark Price from DevSlopes

感谢 DevSlopes 的 Mark Price

回答by KARTHIKEYAN.A

check package.json file having "scripts" property is there or not. if not update script property like this

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

{
  "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"
}

回答by Yream

In my case, if it's a react project, you can try to upgrade npm, and then upgrade react-cli

就我而言,如果是react项目,可以尝试升级npm,然后升级react-cli

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

回答by Basilisk Wise

Installing create-react-app globally is now discouraged. Instead uninstall globally installed create-react-app package by doing: npm uninstall -g create-react-app (you may have to manually delete package folder if this command didn't work for you. Some users have reported they had to delete folders manually)

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

Then you can run npx create-react-app my-app to create react app again.

然后你可以运行 npx create-react-app my-app 再次创建反应应用程序。

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

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

回答by Deva

should avoid using unstable npm version.

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

I observed one thing that is npm version based issue, npm version 4.6.1 is the stable one but 5.x is unstable because package.json will be configured perfectly while creating with default template if it's a stable versionand so we manually don't need to add that scripts.

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

I got the below issue on the npm 5 so I downgraded to npm 4.6.1 then its worked for me,

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



ERROR: npm 5 is not supported yet

错误:尚不支持 npm 5



It looks like you're using npm 5 which was recently released.

看起来您正在使用最近发布的 npm 5。

Create React Native App doesn't work with npm 5 yet, unfortunately. We recommend using npm 4 or yarn until some bugs are resolved.

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

You can follow the known issues with npm 5 at: https://github.com/npm/npm/issues/16991

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



Devas-MacBook-Air:SampleTestApp deva$ npm start npm ERR! missing script: start

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

回答by kbooth1000

Another possible reason: you're using npm when your project is initialized in yarn. (I did this myself). So it would be yarn startinstead of npm start.

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