Node.js 应用无法使用 Node-gyp 在 Azure 网站上部署



我已经建立了一个Azure网站,我正在尝试使用一个依赖于node-gyp的示例应用程序。

我得到这个:

emote: > node-expat@2.0.0 install C:DWASFilesSitesnode-canvasVirtualDirectory0sitewwwrootnode_modulesnode-salesforcenode_modulesxml2jsonnode_modulesnode-expat
remote: > node-gyp rebuild
remote: 
remote: 
remote: C:DWASFilesSitesnode-canvasVirtualDirectory0sitewwwrootnode_modulesnode-salesforcenode_modulesxml2jsonnode_modulesnode-expat>node "D:Program Files (x86)npm1.2.18binnode-gyp-bin\....node_modulesnode-gypbinnode-gyp.js" rebuild 
remote: Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
remote: MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe". To fix this, 1) install the .NET Framework 2.0 SDK, 2) install Microsoft Visual Studio 2005 or 3) add the location of the component to the system path if it is installed elsewhere.  [C:DWASFilesSitesnode-canvasVirtualDirectory0sitewwwrootnode_modulesnode-salesforcenode_modulesxml2jsonnode_modulesnode-expatbuildbinding.sln]
remote: gypnpm ERR! node-expat@2.0.0 install: `node-gyp rebuild`
remote: npm ERR! `cmd "/c" "node-gyp rebuild"` failed with 1
remote: npm ERR! 
remote: An error has occurred during web site deployment.
remote: npm ERR! Failed at the node-expat@2.0.0 install script.
remote: npm ERR! This is most likely a problem with the node-expat package,
remote: npm ERR! not with npm itself.
remote: npm ERR! Tell the author that this fails on your system:
remote: npm ERR!     node-gyp rebuild
remote: npm ERR! You can get their info via:
remote: npm ERR!     npm owner ls node-expat
remote: npm ERR! There is likely additional logging output above.
remote: 
remote: npm ERR! System Windows_NT 6.2.9200
remote: npm ERR! command "D:\Program Files (x86)\nodejs\0.8.19\node.exe" "D:\Program Files (x86)\npm\1.2.18\bin\npm-cli.js" "install" "--production"
remote: npm ERR! cwd C:DWASFilesSitesnode-canvasVirtualDirectory0sitewwwroot
remote: npm ERR! node -v v0.8.19
remote: npm ERR! npm -v 1.2.18
remote: npm ERR! code ELIFECYCLE
remote: npm
remote: 
remote: Error - Changes committed to remote repository but deployment to website failed, please check log for further details.
To https://mike@node-canvas.scm.azurewebsites.net:443/node-canvas.git
   ef20ef4..147856f  master -> master

人们是否对此有优雅的解决方案,或者我是否需要启动 Linux VM 并像这样部署应用程序?

网站限制。请参阅 http://azure.microsoft.com/en-us/documentation/articles/nodejs-use-node-modules-azure-apps/的本机模块部分。

解决方法

/解决方法是将所有模块安装在 Windows 开发盒上,并将node_modules作为 git 部署的一部分包含在内。

我最近成功部署了一个 Node.js 应用程序/Sails 应用程序作为依赖于 Grunt 的 Azure Web 应用程序运行,因此也需要对 node-gyp 的支持。起初,我努力让node-gyp在不包括node_modules文件夹的情况下在持续部署上运行,但最终我成功地获得了一个您希望称之为"优雅解决方案"的东西。对我来说必要的步骤是:

  1. 请确保使用最新版本的 Node 和 NPM(只要 Azure 允许你这样做:(。就我而言,我使用了节点 5.4.0 和 npm 3.3.12。在 Azure 上部署,我知道有两种方法可以做到这一点:

    • 应用程序设置:WEBSITE_NODE_DEFAULT_VERSION 5.4.0(或其他(
    • Package.json 文件:包括以下内容:

      "engines": {    
          "node": "5.4.0",    
          "npm": "3.3.12"  
      },
      
  2. 更改 config/env/production.js 文件中的设置,让咕噜咕噜有更多的时间来丑化或其他什么。对于许多应用程序来说,默认值 20s 似乎太低了,但是可能有更好的方法来解决这个问题:https://github.com/balderdashy/sails/issues/2691我把:

    hookTimeout: 60000, // 60 seconds
    
  3. 我使用 .deployment 和 deploy.cmd/deploy.sh(具体取决于您的系统(文件来自定义 Azure 平台上的部署。我使用的指南是:http://www.cptloadtest.com/2013/12/03/Git-And-Grunt-Deploy-To-Windows-Azure.aspx

    编辑:看起来我从deploy.cmd运行Grunt的原始命令不正确,我不熟悉bash脚本,抱歉。我最终使用了这个问题中的脚本,并进行了一些修改:将 NodeJS 应用程序部署到 Azure 网站在从 deploy.cmd 的 pagages.json 安装 NPM 包时失败?
    使用此脚本,我的 grunt 任务在部署上运行。这是我脚本的修改部分。
    部署.cmd:

    :: Setup
    :: -----        
    :: ... some default parts omitted
    IF NOT DEFINED GRUNT_CMD (
      :: Install grunt
      echo Installing Grunt
      call npm --registry "http://registry.npmjs.org/" install grunt-cli
      IF !ERRORLEVEL! NEQ 0 goto error
      :: Locally just running "grunt" would also work
    SET GRUNT_CMD=node "%DEPLOYMENT_SOURCE%node_modulesgrunt-clibingrunt"
    )
    goto Deployment
    :: Utility Functions
    :: -----------------
    :SelectNodeVersion
    :: ... some default parts omitted
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :Deployment
    echo Handling node.js deployment.
    echo %DEPLOYMENT_SOURCE%
    echo 1. Select node version
    call :SelectNodeVersion
    echo 2. Install npm packages dev dependencies
    IF EXIST "%DEPLOYMENT_SOURCE%package.json" (
      pushd "%DEPLOYMENT_SOURCE%"
      echo Cleaning NPM cache.
      call !NPM_CMD! cache clean
      call !NPM_CMD! install --development
      IF !ERRORLEVEL! NEQ 0 goto error
      popd
    )        
    echo 4. Run grunt prod task
    pushd %DEPLOYMENT_SOURCE%
    call !GRUNT_CMD! --no-color prod
    IF !ERRORLEVEL! NEQ 0 goto error
    popd
    echo 5. KuduSync
    IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" (
      call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_SOURCE%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd"
      IF !ERRORLEVEL! NEQ 0 goto error
    )
    echo 6. Install npm packages production
    IF EXIST "%DEPLOYMENT_TARGET%package.json" (
      pushd %DEPLOYMENT_TARGET%
      call !NPM_CMD! install --production
      IF !ERRORLEVEL! NEQ 0 goto error
      popd
    )
    
  4. 然后我遇到了这个错误:使用 Grunt 的 ENOTSUP 幸运的是最近解决了:)
    剩下我要做的就是更改给定 deploy.sh 语法以在我的 deploy.cmd 中工作。因此,在从deploy.cmd运行grunt之前,我包括:

    echo 3. Update erroneous glob dependency in Grunt 
    pushd "%DEPLOYMENT_SOURCE%node_modulesgrunt"
    call :ExecuteCmd !NPM_CMD! install glob@^6.0.4 --save
    IF !ERRORLEVEL! NEQ 0 goto error
    popd
    

我希望这对你们中的一些人有所帮助,尽管我知道,我面临的一些问题可能会使用最新版本的 node 和 npm 来解决。但是,由于 Azure 没有开箱即用地提供最新版本,因此对你们中的某些人可能仍然有帮助。

编辑:

关于:

  1. 节点版本选择:

    我尝试通过在 Package.json 中设置节点版本来选择节点版本,而不更改应用程序设置(默认版本:4.2.3(中的默认设置,但仍然收到以下错误:

    Node.js versions available on the platform are: 0.6.20, 0.8.2, 0.8.19, 0.8.26, 0.8.27, 0.8.28, 0.10.5, 0.10.18, 0.10.21, 0.10.24, 0.10.26, 0.10.28, 0.10.29, 0.10.31, 0.10.32, 0.10.40, 0.12.0, 0.12.2, 0.12.3, 0.12.6, 4.0.0, 4.1.0, 4.1.2, 4.2.1, 4.2.2, 4.2.3, 4.2.4, 5.0.0, 5.1.1, 5.3.0, 5.4.0, 5.5.0.
    Selected node.js version 5.4.0. Use package.json file to choose a different version.
    Selected npm version 3.3.12
    Updating iisnode.yml at D:homesitewwwrootiisnode.yml
    3. Install npm packages
    npm WARN deprecated lodash@0.9.2: lodash@<2.0.0 is no longer maintained. Upgrade to lodash@^3.0.0
    npm WARN deprecated grunt-lib-contrib@0.7.1: DEPRECATED. See readme: https://github.com/gruntjs/grunt-lib-contrib
    npm WARN deprecated lodash@1.0.2: lodash@<2.0.0 is no longer maintained. Upgrade to lodash@^3.0.0
    > sails@0.11.4 preinstall D:homesitewwwrootnode_modules.stagingsails-bbe9b0ace9f7789c8522238af14fe27a
    > node ./lib/preinstall_npmcheck.js
    Sails.js Installation: Checking npm-version successful
    npm WARN prefer global grunt-cli@0.1.13 should be installed with -g
    > fibers@1.0.8 install D:homesitewwwrootnode_modulesfibers
    > node build.js || nodejs build.js
    
    D:homesitewwwrootnode_modulesfibers>if not defined npm_config_node_gyp (node "c:Program Files (x86)npm3.3.12node_modulesnpmbinnode-gyp-bin\....node_modulesnode-gypbinnode-gyp.js" rebuild --release )  else (node  rebuild --release ) 
    Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
      fibers.cc
      coroutine.cc
    ..srcfibers.cc : fatal error C1902: Program database manager mismatch; please check your installation [D:homesitewwwrootnode_modulesfibersbuildfibers.vcxproj]
    ..srccoroutine.cc : fatal error C1902: Program database manager mismatch; please check your installation [D:homesitewwwrootnode_modulesfibersbuildfibers.vcxproj]
    gyp ERR! build error 
    gyp ERR! stack Error: `msbuild` failed with exit code: 1
    gyp ERR! stack     at ChildProcess.onExit (c:Program Files (x86)npm3.3.12node_modulesnpmnode_modulesnode-gyplibbuild.js:270:23)
    gyp ERR! stack     at emitTwo (events.js:87:13)
    gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
    gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
    gyp ERR! System Windows_NT 6.2.9200
    gyp ERR! command "D:\Program Files (x86)\nodejs\4.2.3\node.exe" "c:\Program Files (x86)\npm\3.3.12\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild" "--release"
    gyp ERR! cwd D:homesitewwwrootnode_modulesfibers
    gyp ERR! node -v v4.2.3
    gyp ERR! node-gyp -v v3.0.3
    Build failed
    

    就像你首先看到的那样:

    Selected node.js version 5.4.0. Use package.json file to choose a different version.
    

    根据 Package.json 文件。
    但是,稍后在错误消息中,这似乎已更改:

    gyp ERR! node -v v4.2.3
    
    对我来说,为什么

    会发生此错误并不明显,因为 Package.json 文件中的版本应该覆盖应用程序设置中的默认值。因此,可以肯定的是,只需将两个设置都设置为足够高的版本(不确定何时解决了node-gyp问题,但是5.4.0似乎工作正常!

最新更新