简体   繁体   English

npm start - npm 错误! 缺少脚本:开始

[英]npm start - npm ERR! missing script: start

I'm receiving this error when trying to my node application using the npm start command.尝试使用 npm start 命令运行我的节点应用程序时,我收到此错误。

WhenIi try to npm start I get this error.当我尝试 npm start 时出现此错误。

Error:错误:

 0 info it worked if it ends with ok
    1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
    1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
    1 verbose cli   'start' ]
    2 info using npm@5.6.0
    3 info using node@v8.10.0
    4 verbose stack Error: missing script: start
    4 verbose stack     at run (C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:151:19)
    4 verbose stack     at C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:61:5
    4 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:115:5
    4 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:402:5
    4 verbose stack     at checkBinReferences_ (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:357:45)
    4 verbose stack     at final (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:400:3)
    4 verbose stack     at then (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:160:5)
    4 verbose stack     at ReadFileContext.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:332:20)
    4 verbose stack     at ReadFileContext.callback (C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:78:16)
    4 verbose stack     at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:420:13)
    5 verbose cwd B:\tut\starter
    6 verbose Windows_NT 6.1.7601
    7 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
    8 verbose node v8.10.0
    9 verbose npm  v5.6.0
    10 error missing script: start
    11 verbose exit [ 1, true ]

From the debug file:从调试文件:

{
  "name": "sridhar",
  "version": "1.0.0",
  "description": "landing page",
  "main": "index.js",
  "scripts": {
    "compile:sass": "node-sass sass/main.scss  css/style.css -w"
  },
  "author": "sridhar",
  "license": "ISC",
  "devDependencies": {
    "node-sass": "^4.8.3"
  }
}

You are missing the entry start in the scripts section of your package.json .您缺少package.jsonscripts部分中的条目start If you want to compile the file using npm start then, you should copy node-sass sass/main.scss css/style.css -w and paste it as a value for start .如果要使用npm start编译文件,则应复制node-sass sass/main.scss css/style.css -w并将其粘贴为start的值。 You can add any command you would like to execute as the value for start.您可以添加任何您想要执行的命令作为启动值。

Having said that, if you do npm "compile:sass" it will compile your sass files if you don't want to change your package.json .话虽如此,如果您执行npm "compile:sass" ,如果您不想更改package.json ,它将编译您的 sass 文件。

"scripts": {
    ...
    "compile:sass": "node-sass sass/main.scss  css/style.css -w",
     "start": "node-sass sass/main.scss  css/style.css -w"
  },

Because there is no start script... Just change compile script to start script... Then it will compile your sass files...因为没有启动脚本......只需将编译脚本更改为启动脚本......然后它就会编译你的sass文件......

"scripts": {
  "start": "node-sass sass/main.scss  css/style.css -w"
},

npx proved to be more effective to me, instead of using npm after several trials. npx 被证明对我更有效,而不是经过多次试验后使用 npm。

The below code worked for me:以下代码对我有用:

npx babel --watch src --out-dir . npx babel --watch src --out-dir 。 --presets react-app/prod --presets react-app/prod

It did not require me to manually edit the package.json anymore.它不再需要我手动编辑 package.json。 Everything went smooth.一切都很顺利。

For more information please refer to the official documentation page https://reactjs.org/docs/add-react-to-a-website.html#optional-try-react-with-jsx更多信息请参考官方文档页面https://reactjs.org/docs/add-react-to-a-website.html#optional-try-react-with-jsx

Cheers干杯

尝试删除npx ,只需使用create-react-app itworks

You should remove whatever is there in the script object (If you have just created the project) in package.json file, and put these two lines in.您应该删除 package.json 文件中脚本对象(如果您刚刚创建项目)中的任何内容,并将这两行放入。

"start": "webpack-dev-server --mode development --open --hot", "build": "webpack --mode production"

Folks forget to do that sometimes.And leave the "test" case in. Also make sure you have installed all the dependencies you need for your project, from webpack-cli to other stuff mentioned in the error stack trace.人们有时会忘记这样做。并将“测试”案例留在里面。还要确保您已经安装了项目所需的所有依赖项,从 webpack-cli 到错误堆栈跟踪中提到的其他内容。

Hope this works.希望这有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM