通过deploy.cmd文件在天蓝色Web应用程序部署中Grunt安装失败

时间:2016-06-15 18:52:34

标签: git azure deployment bower grunt-cli

我尝试使用Azure的Git部署来构建和打包我的项目。

我创建了以下文件

  1. .deployment
  2. deploy.cmd
  3. Gruntfile.js
  4. 的package.json
  5. bower.json
  6. 我跟随Jay Harris的blog post。下面给出了deploy.cmd文件中的部署部分:

    :: 2. Select node version
    call :SelectNodeVersion
    
    :: 3. Install npm packages
    IF EXIST "%DEPLOYMENT_TARGET%\package.json" (
      pushd "%DEPLOYMENT_TARGET%"
      call :ExecuteCmd !NPM_CMD! install --production
      IF !ERRORLEVEL! NEQ 0 goto error
      popd
    )
    
    :: 4. Install bower packages
    IF EXIST "%DEPLOYMENT_TARGET%\bower.json" (
      call !NPM_CMD! install bower
      IF !ERRORLEVEL! NEQ 0 goto error
      call .\node_modules\.bin\bower install
      IF !ERRORLEVEL! NEQ 0 goto error
    )
    
    :: 4. run grunt
    IF EXIST "%DEPLOYMENT_TARGET%\Gruntfile.js" ( 
      call !NPM_CMD! install grunt-cli  
      call .\node_modules\.bin\grunt --no-color clean common dist
      IF !ERRORLEVEL! NEQ 0 goto error
    )
    

    部署失败并出现以下错误:

    Selected npm version 3.8.6
    Updating iisnode.yml at D:\home\site\wwwroot\iisnode.yml
    spa@ D:\home\site\wwwroot
    +-- bower@1.7.9  extraneous
    npm WARN grunt-contrib-compass@1.0.4 requires a peer of grunt@>=0.4.0 but none was installed.
    +-- UNMET PEER DEPENDENCY grunt@>=0.4.0
    `-- grunt-cli@1.2.0  extraneous
    
    spa@ D:\home\site\repository
    `-- bower@1.7.9  extraneous
    
    spa@ D:\home\site\repository
    +-- bower@1.7.9  extraneous
    `-- grunt-cli@1.2.0  extraneous
    
    grunt-cli: The grunt command line interface (v1.2.0)
    
    Fatal error: Unable to find local grunt.
    
    If you're seeing this message, grunt hasn't been installed locally to
    your project. For more information about installing and configuring grunt,
    please see the Getting Started guide:
    
    http://gruntjs.com/getting-started
    An error has occurred during web site deployment.
    npm WARN grunt-contrib-compass@1.0.4 requires a peer of grunt@>=0.4.0 but none was installed.\r\nC:\Program Files (x86)\SiteExtensions\Kudu\55.50610.2267\bin\Scripts\starter.cmd deploy.cmd
    

    我不确定我还需要做什么来安装它。试图通过网络搜索类似的问题,但无法找到问题的具体解决方案。如果有人能帮助我,那就太好了。

    我的package.json

    {
      "name": "myapp",
      "private": true,
      "devDependencies": {
        "autoprefixer-core": "^5.2.1",
        "grunt": "^0.4.5",
        "grunt-angular-templates": "^0.5.7",
        "grunt-concurrent": "^1.0.0",
        "grunt-contrib-clean": "^0.6.0",
        "grunt-contrib-compass": "^1.0.0",
        "grunt-contrib-concat": "^0.5.0",
        "grunt-contrib-connect": "^0.9.0",
        "grunt-contrib-copy": "^0.7.0",
        "grunt-contrib-cssmin": "^0.12.0",
        "grunt-contrib-htmlmin": "^0.4.0",
        "grunt-contrib-imagemin": "^1.0.0",
        "grunt-contrib-jshint": "^0.11.0",
        "grunt-contrib-uglify": "^0.7.0",
        "grunt-contrib-watch": "^0.6.1",
        "grunt-filerev": "^2.1.2",
        "grunt-google-cdn": "^0.4.3",
        "grunt-jscs": "^1.8.0",
        "grunt-newer": "^1.1.0",
        "grunt-ng-annotate": "^0.9.2",
        "grunt-postcss": "^0.5.5",
        "grunt-svgmin": "^2.0.0",
        "grunt-usemin": "^3.0.0",
        "grunt-wiredep": "^2.0.0",
        "imagemin": "^5.2.1",
        "jasmine-core": "^2.4.1",
        "jit-grunt": "^0.9.1",
        "jshint-stylish": "^1.0.0",
        "karma": "^0.13.22",
        "karma-jasmine": "^1.0.2",
        "karma-phantomjs-launcher": "^1.0.0",
        "phantomjs-prebuilt": "^2.1.7",
        "readable-stream": "^2.1.4",
        "through2": "^2.0.1",
        "time-grunt": "^1.0.0",
        "vinyl-fs": "^2.2.1"
      },
      "engines": {
        "node": ">=0.10.0"
      },
      "scripts": {
        "test": "karma start test\\karma.conf.js"
      }
    }
    

    注意:到目前为止还没有找到解决方案,我会去Azure支持团队找出我能做的事情。一旦找到任何解决方案,我就会更新问题。

2 个答案:

答案 0 :(得分:2)

大多数similar questions(不是为了azure)指向:

npm install grunt --save-dev
npm install -g grunt --save-dev

(如果要从脚本中使用-g,请尝试全局grunt安装

This thread提及应该安装grunt并在PATH中显示为azure:

  

问题不在于路径上找不到grunt(" D:\Program Files (x86)\grunt\0.1.13\grunt")。它肯定会开始运行,但它的grunt本身就会抱怨   如果我到Kudu控制台并运行' grunt'从D:\home\site\repository文件夹中,它显示的内容完全相同。

projectkudu/kudu Issue 1150确认:

  

在本地运行Kudu(即在Azure之外)时不会发生这种情况   因此,Azure网站上的运行时环境可能会出现问题。

grunt issue 1459所示,请检查退出状态错误代码:

$ echo $?
99
  

我们将首先重命名node_modules/grunt目录,以便grunt-cli无法找到本地grunt。这应该导致错误代码99。

     

预期的结果会让我相信误导性的grunt-cli错误消息让开发人员误以为Grunt本身正在返回错误的错误代码。

因此,在Azure的情况下,可能会在路径上安装grunt,但不会在grunt-cli预期的位置安装。

答案 1 :(得分:2)

控制你的package.json有以下行。

"devDependencies": {
    "grunt": "~0.4.5",
 ..
 }

Grunt-cli期待您项目中的当地咕噜声。这个错误

  

致命错误:无法找到当地的咕噜声。

是关于这个本地的grunt。因为你的脚本已经执行 npm install ,所以你需要做的就是添加“grunt”:“~0.4.5”行到你的package.json在依赖项中。

以下命令也做同样的事情,即向devDependencies添加grunt。

npm install grunt --save-dev