运行npm start

时间:2015-08-12 22:51:55

标签: javascript node.js express package.json npm-scripts

尝试使用npm start命令调试节点应用程序时收到此错误。

错误:

  

npm ERR! Windows_NT 6.3.9600   错误的ERR! argv“C:\ Program Files \ nodejs \\ node.exe”“C:\ Program Files \ nodejs \ node_modules \ npm \ bin \ npm-cli.js”“start”   错误的ERR!节点v0.12.7   错误的ERR! npm v2.11.3

     

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

来自调试文件:

  

详细堆栈错误:缺少脚本:启动

     

运行时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

的详细堆栈      

checkBinReferences_上的4个详细堆栈(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

的详细堆栈      

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

28 个答案:

答案 0 :(得分:288)

您可能没有在start文件中定义package.json脚本,或者您的项目中不包含server.js文件。

  

如果包的根目录中有server.js文件,则npm会将start命令默认为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

答案 1 :(得分:35)

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

答案 2 :(得分:27)

在我的情况下,它无效,因为我使用了"scripts" 两次。合并后 - 没关系。

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

答案 3 :(得分:3)

请使用package.json

中的脚本对象中的以下代码行
"scripts": {
    "start": "webpack-dev-server --hot"
}

对我而言,它的效果非常好。

答案 4 :(得分:3)

如果您正在使用babelify并观察,请访问:

的package.json

并在“脚本”中添加:

map

一个例子是:

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

感谢DevSlopes的Mark Price

答案 5 :(得分:3)

您可能安装了旧的(全局)npm安装导致了此问题。从12/19开始,npm不支持全局安装。

首先,使用以下命令卸载软件包:
npm uninstall -g create-react-app

某些osx / Linux用户可能还需要使用以下命令删除旧的npm: rm -rf /usr/local/bin/create-react-app

现在是生成项目的唯一受支持的方法:
npx create-react-app my-app

最后您可以运行:
npm start

答案 6 :(得分:2)

尝试执行以下步骤:

npm rm -g create-react-app

npm install -g create-react-app

npx create-react-app my-app

绝对可以!!

答案 7 :(得分:1)

检查包含"脚本"的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"
}

答案 8 :(得分:1)

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

然后,您可以运行npx create-react-app my-app再次创建react应用。

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

答案 9 :(得分:1)

确保端口打开

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

BLAL BLA BLA和你有这个结束

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

仍然是节点js中的新手,但这引起了更多。

答案 10 :(得分:0)

希望它可以帮助某人。 如果您没有从项目的根目录打开项目,也会发生此错误。在 VS 代码中打开文件夹之前,请确保先 cd 进入该文件夹。

答案 11 :(得分:0)

我第一次安装 react-js 时遇到了类似的问题:这些行帮助我解决了这个问题:

npm uninstall -g create-react-app
npm rm -g create-react-app
npm install -g create-react-app
npx create-react-app my-app

这在我的情况下有效。

答案 12 :(得分:0)

我遇到了同样的问题。我试图在 VS 代码终端上启动它。所以我在我的电脑终端(不是在 VS Code 里面)启动开发环境。有效。启动前请确保您在终端中的文件内

答案 13 :(得分:0)

试试这个方法对你有用
Try this Method it will work 100 %

答案 14 :(得分:0)

我刚刚偶然发现了这个问题。我重新安装了 NPM,创建了一个新的 React 应用程序(所以基本上是全新安装),但仍然没有运气。 终于搞清楚了:

我的终端不在在正确的位置。

我不得不将目录更改为更深一层的应用程序。 所以我的终端在我的“projects”文件夹而不是我的“my-app”文件夹

路径:'/Documents/projects/my-app'

答案 15 :(得分:0)

我收到此错误是因为我不在终端中的正确目录中。

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

答案 16 :(得分:0)

我在Rails应用程序上使用ruby遇到此错误,我不知道要在package.json文件中放置什么脚本名称。我尝试过:

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

但是我得到了这个错误:

remote: App container failed to start!!
=====> taaalk web container output:
       > taaalk_edge@0.1.0 start
       > webpack-dev-server --hot
       /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- bundler/setup (LoadError)
        from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        from /app/bin/webpack-dev-server:10:in `<main>'
       npm ERR! code 1
       npm ERR! path /app
       npm ERR! command failed
       npm ERR! command sh -c webpack-dev-server --hot
       npm ERR! A complete log of this run can be found in:
       npm ERR!     /app/.npm/_logs/2020-11-27T01_01_54_386Z-debug.log
       > taaalk_edge@0.1.0 start
       > webpack-dev-server --hot
       /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- bundler/setup (LoadError)
        from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        from /app/bin/webpack-dev-server:10:in `<main>'
       npm ERR! code 1
       npm ERR! path /app
       npm ERR! command failed
       npm ERR! command sh -c webpack-dev-server --hot
       npm ERR! A complete log of this run can be found in:
       npm ERR!     /app/.npm/_logs/2020-11-27T01_01_55_590Z-debug.log
       > taaalk_edge@0.1.0 start
       > webpack-dev-server --hot
       /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- bundler/setup (LoadError)
        from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        from /app/bin/webpack-dev-server:10:in `<main>'
       npm ERR! code 1
       npm ERR! path /app
       npm ERR! command failed
       npm ERR! command sh -c webpack-dev-server --hot
       npm ERR! A complete log of this run can be found in:
       npm ERR!     /app/.npm/_logs/2020-11-27T01_01_56_835Z-debug.log
       > taaalk_edge@0.1.0 start
       > webpack-dev-server --hot
       /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- bundler/setup (LoadError)
        from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        from /app/bin/webpack-dev-server:10:in `<main>'
       npm ERR! code 1
       npm ERR! path /app
       npm ERR! command failed
       npm ERR! command sh -c webpack-dev-server --hot
       npm ERR! A complete log of this run can be found in:
       npm ERR!     /app/.npm/_logs/2020-11-27T01_01_58_249Z-debug.log
       > taaalk_edge@0.1.0 start
       > webpack-dev-server --hot
       /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- bundler/setup (LoadError)
        from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        from /app/bin/webpack-dev-server:10:in `<main>'
       npm ERR! code 1
       npm ERR! path /app
       npm ERR! command failed
       npm ERR! command sh -c webpack-dev-server --hot
       npm ERR! A complete log of this run can be found in:
       npm ERR!     /app/.npm/_logs/2020-11-27T01_02_00_063Z-debug.log
       > taaalk_edge@0.1.0 start
       > webpack-dev-server --hot
       /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- bundler/setup (LoadError)
        from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        from /app/bin/webpack-dev-server:10:in `<main>'
       npm ERR! code 1
       npm ERR! path /app
       npm ERR! command failed
       npm ERR! command sh -c webpack-dev-server --hot
       npm ERR! A complete log of this run can be found in:
       npm ERR!     /app/.npm/_logs/2020-11-27T01_02_02_705Z-debug.log
=====> end taaalk web container output
To taaalk.co:taaalk
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'dokku@taaalk.co:taaalk'

我对这类问题不是很熟悉,所以有点迷路!

答案 17 :(得分:0)

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

npx create-react-app my-app cd my-app npm开始

答案 18 :(得分:0)

当我尝试运行“npm run start”时遇到了同样的错误

我的项目应该以“npm run serve”开头

如果你复制一个 github 项目,你可以像这样查看项目设置: enter image description here

所以始终确保使用正确的命令运行它,在我的情况下是

npm run serve

答案 19 :(得分:0)

看看您的 client / package.json 。您必须拥有这些脚本

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

答案 20 :(得分:0)

就我而言,如果它是一个React项目,则可以尝试升级npm,然后再升级react-cli

import requests
import urllib.request
import re
from bs4 import BeautifulSoup

r = requests.get('https://ghalliance.org/resource/bible-reading')
soup = BeautifulSoup(r.content, 'html.parser')

for a in soup.find_all('a', href=re.compile('http.*\.mp3')):
    print(a['href'])

答案 21 :(得分:0)

我有同样的问题。我尝试在package.json文件中编写如下代码

    "scripts": {
    "start": "<your-script-file>.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },

答案 22 :(得分:0)

如果您同时运行两个应用程序,请关闭其中一个,然后构建并运行应用程序

答案 23 :(得分:0)

另一个可能的原因:当您在yarn中初始化项目时,您正在使用npm。 (我自己做的)。因此它将是yarn start而不是npm start

答案 24 :(得分:0)

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

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

我在npm 5上遇到了以下问题所以我降级到npm 4.6.1然后它为我工作了,

错误:不支持npm 5

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

不幸的是,创建React Native App并不适用于npm 5。我们 建议使用npm 4或纱线,直到一些错误得到解决。

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

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

答案 25 :(得分:0)

我已经解决了我的问题。它不是与代理行为相关的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"

答案 26 :(得分:0)

"scripts": {
  "prestart": "npm install",
  "start": "http-server -a localhost -p 8000 -c-1"
}

package.json 中添加此代码段,具体取决于您自己的配置。

答案 27 :(得分:-1)

就我而言,以下代码可以正常工作。.

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "parcel index.html",
"build": "parcel build --public-url . index.html"  }