当我试图用npm start命令调试我的节点应用程序时,我收到了这个错误。

Error:
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
From the debug file:
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)

当前回答

关于脚本还有更多的答案。这是我的两分钱。如果你有同样的问题刚刚创建react应用程序或刚开始在一天的工作,在大多数情况下,这就是发生了什么。您可能无法进入创建的项目。

假设你创建了一个react应用my-app。然后,在运行NMP start命令之前,必须进入应用程序内部。

1. 我的程序光盘

2. npm开始

它会工作得很好。

其他回答

我也有同样的问题。我试图在VS code终端启动它。所以我在我的计算机终端中启动开发环境(而不是在VS Code中)。它工作。在启动该文件之前,请确保您在终端中的文件中

看起来您可能没有在包中定义开始脚本。Json文件或您的项目不包含server.js文件。

如果在你的包的根目录中有一个server.js文件,那么npm将默认启动命令到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

我得到这个错误,因为我不在终端的正确目录。

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

确保端口是打开的

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

诸如此类,最后你得到了这个

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

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

我已经解决了我的问题。这不是一个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"