如何修复 npm ERR! missing script: start
问题:
你想使用以下命令运行 NodeJS 应用
npm-start.sh
npm start但你只看到此错误消息:
npm-error.txt
npm ERR! missing script: start解决方案
你需要通过编辑 package.json 明确告诉 npm 在你运行 npm start 时做什么。
首先,确定你的应用程序的主文件。通常它称为 index.js、server.js 或 app.js。当你在编辑器中打开 package.json 时,你通常还可以找到类似这样的行
package-main.js
"main": "index.js",在此示例中,index.js 是应用程序的主文件。
现在我们可以编辑 package.json 以添加 start 脚本。
在 package.json 中,找到 "scripts" 部分。如果你有默认的 package.json,它将如下所示:
package-scripts.js
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},现在在 "test" 行末添加逗号并在其后添加此行:
package-start.json
"start": "node index.js"并将 index.js 替换为你的应用程序的主文件(例如 app.js、server.js、index.js 等)。
现在 "scripts" 部分应如下所示:
package-scripts-final.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},现在保存并关闭 package.json 并运行
npm_start_run.sh
npm start以启动你的应用程序。
Check out similar posts by category:
Javascript, NodeJS
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow