当我试图用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)

当前回答

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

其他回答

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

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

添加这个内部包。Json文件。

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

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

package.json

并在“脚本”中添加这个:

"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的Mark Price

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

首先,使用以下方法卸载包: NPM卸载-g create-react-app

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

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

最后你可以运行: npm开始

根据react文档https://create-react-app.dev/docs/getting-started/ 下面的命令将解决这个问题。

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