【问题标题】:Start script missing error when running npm start运行 npm start 时启动脚本丢失错误
【发布时间】:2015-11-05 17:48:10
【问题描述】:

我在尝试使用 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 脚本?

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


【解决方案1】:

您可能没有在您的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

【讨论】:

  • 我很难理解,当你有main 时,start 有什么需要?
  • @Val main 是当您使用 require('your-module') 将模块包含在另一个项目中时的入口点 - docs.npmjs.com/files/package.json#mainscripts.start 是 npm 在你输入 npm start 时运行的脚本。
  • 不清楚为什么npm init 不询问启动脚本。或者至少不使用main 作为启动脚本。
  • 无需再做任何事情,只需添加 "scripts": { "prestart": "npm install", "start": "http-server -a localhost -p 8000 -c-1" },
  • 在我的情况下它工作正常.. "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "parcel index.html ", "build": "parcel build --public-url .index.html" },
【解决方案2】:

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

【讨论】:

  • 这个答案可能不是一个准确的回答,但它确实帮助我找到了npm start 不起作用的原因。
  • 这实际上是一个精确的响应。如果您的 package.json 文件包含两个脚本条目,它将选择第二个并忽略您在第一个中记录的任何内容。您将在问题中收到错误消息。
  • @Plamen Petkov,你的意思是scripts 而不是script? (缺少s?)
【解决方案3】:

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

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

对我来说效果很好。

【讨论】:

  • 对我不起作用。你还在用$ npm run serve
【解决方案4】:

如果你使用的是 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

【讨论】:

    【解决方案5】:

    在关闭“}”之前在 package.json 文件中添加这个

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

    【讨论】:

    • index.js 是一个实际的文件吗?还是我们需要创造的东西?
    • @tomsmithweb 我记得 - 这是我现有的文件。
    【解决方案6】:

    确保端口开启

    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'))
    });
    

    仍然是 node js 中的新手,但这导致了更多。

    【讨论】:

      【解决方案7】:
      "scripts": {
        "prestart": "npm install",
        "start": "http-server -a localhost -p 8000 -c-1"
      }
      

      在你的package.json中添加这段代码sn-p,取决于你自己的配置。

      【讨论】:

        【解决方案8】:

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

        【讨论】:

          【解决方案9】:

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

          【讨论】:

            【解决方案10】:

            应避免使用不稳定的 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 错误!缺少脚本:开始

            【讨论】:

              【解决方案11】:

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

              【讨论】:

                【解决方案12】:

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

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

                【讨论】:

                  【解决方案13】:

                  在我的情况下,如果是react项目,可以尝试升级npm,然后升级react-cli

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

                  【讨论】:

                    【解决方案14】:

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

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

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

                    【讨论】:

                      【解决方案15】:

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

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

                      【讨论】:

                        【解决方案16】:

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

                        【讨论】:

                        • 以上对我有用;请注意像我这样的新用户命令 npm rm 将删除 create-react-app
                        【解决方案17】:

                        您可能有一个旧的(全局)安装的 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

                        【讨论】:

                          【解决方案18】:

                          尝试以下步骤:

                          npm rm -g create-react-app

                          npm install -g create-react-app

                          npx create-react-app my-app

                          这绝对有效!!

                          【讨论】:

                            【解决方案19】:

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

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

                            【讨论】:

                              【解决方案20】:

                              我在使用 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'
                              

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

                              【讨论】:

                                【解决方案21】:

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

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

                                【讨论】:

                                  【解决方案22】:

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

                                  我的终端没有在正确的位置。

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

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

                                  【讨论】:

                                    【解决方案23】:

                                    试试这个方法吧

                                    【讨论】:

                                      【解决方案24】:

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

                                      【讨论】:

                                        【解决方案25】:

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

                                        这在我的情况下有效。

                                        【讨论】:

                                        • 用最新的 npm install 来安装 create-react-app,你不应该使用 '-g' 标志
                                        【解决方案26】:

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

                                        【讨论】:

                                          【解决方案27】:

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

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

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

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

                                          npm run serve
                                          

                                          【讨论】:

                                          • 您的克隆项目应该有一个类似“serve”的脚本名称。否则这将不起作用。启动反应项目的默认脚本名称是“start”。但最重要的是您可以将其更改为您想要的任何名称。查看克隆项目的“package.json”文件。在其中,在“script”属性中,您应该会看到类似“serve”:“react-scripts start”或“serve:”:“node index.js”的内容。所以我想,现在你可以理解你的项目中发生了什么。
                                          猜你喜欢
                                          • 2020-06-30
                                          • 2018-05-30
                                          • 1970-01-01
                                          • 2019-02-10
                                          • 2017-06-07
                                          • 1970-01-01
                                          • 2014-11-29
                                          • 1970-01-01
                                          • 1970-01-01
                                          相关资源
                                          最近更新 更多