繁体   English   中英

npm 启动时启动脚本丢失报错

[英]Start script missing error when running npm start

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

错误:
 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
从调试文件:
 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)

看起来您可能没有在package.json文件中定义start脚本,或者您的项目不包含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

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

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

来源: https ://stackoverflow.com/a/59260128/11652661

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

在关闭“}”之前将其添加到 package.json 文件中

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

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

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

我不得不在我的应用程序中更深入地更改目录。 所以我的终端在我的“项目”文件夹中,而不是我的“我的应用”文件夹中

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

您可能有导致问题的旧(全局)安装 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

请在 package.json 中的脚本对象中使用以下代码行

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

对我来说,它工作得很好。

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

试试这个方法,它会为你工作
试试这个方法,它会工作 100%

尝试以下步骤:

npm rm -g create-react-app

npm install -g create-react-app

npx 创建反应应用程序我的应用程序

这绝对有效!

我在第一次安装 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

这在我的情况下有效。

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

包.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

检查具有“脚本”属性的 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"
}

就我而言,如果是react项目,可以尝试升级npm,然后升级react-cli

npm -g install npm@version
npm install -g create-react-app

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

然后你可以运行npx create-react-app my-app再次创建反应应用程序。

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

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

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

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

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

我在 npm 5 上遇到了以下问题,所以我降级到 npm 4.6.1 然后它对我有用,


错误:尚不支持 npm 5


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

不幸的是,Create React Native App 还不能与 npm 5 一起使用。 我们建议使用 npm 4 或 yarn,直到一些错误得到解决。

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


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

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

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

确保端口开启

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 中的新手,但这导致了更多。

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

用这个 :

"scripts": {
  "test": "make test",
  "start": "webpack-dev-server --hot"
  }

在我的情况下,下面的代码工作正常。

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

看看你的client/package.json 你必须有这些脚本

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

我在使用 ruby​​ on rails 应用程序时遇到此错误,我不知道要在 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'

我对这些问题不是很熟悉所以有点迷茫!

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

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

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

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

如果你复制一个 github 项目,你可以像这样查看项目设置: 在此处输入图像描述

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

npm run serve

检查 package.json 文件并在此文件中找到您的脚本名称

vscode创建一个反应项目后,我遇到了这个错误。 关闭并重新打开vscode并在vscode中以cmd模式新建终端后,问题解决。

关于脚本有更多的答案。 这是我的 2 美分。 如果您在创建 React 应用程序后遇到同样的问题,或者刚刚开始工作,在大多数情况下,这就是发生的事情。 您可能没有进入创建的项目。

假设您创建了一个 React 应用程序作为 my-app。 那么在运行 nmp start 命令之前,您必须在应用程序内部输入 go。

1. cd 我的应用程序

2. npm开始

它会工作正常。

检查您是否安装了 nodemon,如果安装了,请使用 package.json 示例 nodemon 启动中的 nodemon 启动脚本运行脚本

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

:重要:确保您需要将目录更改为 my-app 然后点击“npm start”

正如您在图像中看到的那样,有一个错误,并在更改目录后得到修复。 在此处输入图像描述

对于我的示例,我在“First”文件夹中创建了 React 项目,并在此文件夹中运行项目,所以我看到了同样的错误。 你应该进入项目然后你应该运行(对于我的例子“react-movies”)。 如果你看我的 powershell 屏幕,你可以很容易地意识到。

在此处输入图像描述

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

根据您自己的配置,将此代码段添加到您的package.json中。

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

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

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

暂无
暂无

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

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