使用node-gyp的Node.js应用在Azure网站上部署失败

12

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

但是我遇到了这个问题:

emote: > node-expat@2.0.0 install C:\DWASFiles\Sites\node-canvas\VirtualDirectory0\site\wwwroot\node_modules\node-salesforce\node_modules\xml2json\node_modules\node-expat
remote: > node-gyp rebuild
remote: 
remote: 
remote: C:\DWASFiles\Sites\node-canvas\VirtualDirectory0\site\wwwroot\node_modules\node-salesforce\node_modules\xml2json\node_modules\node-expat>node "D:\Program Files (x86)\npm\1.2.18\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-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:\DWASFiles\Sites\node-canvas\VirtualDirectory0\site\wwwroot\node_modules\node-salesforce\node_modules\xml2json\node_modules\node-expat\build\binding.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:\DWASFiles\Sites\node-canvas\VirtualDirectory0\site\wwwroot
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 虚拟机并像那样部署应用程序?


你能够将你的项目发布到Azure吗?我使用node-canvas模块也遇到了同样的问题。 - psousa
2个回答

10

2
这并不是一个好的解决方案,自2013年10月以来有任何更新吗? - Dinis Cruz
1
根据#1076,它应该正常工作。另一个可用的选择是VSTS Hosted Build,它具有所有必需的依赖项(已测试并且完美运行)。 - Jan Hajek
请记得在您安装的应用服务/网站上启用Python :) - Hulvej
现在它可以工作了,但不适用于免费/共享站点。 https://feedback.azure.com/forums/169385-web-apps-formerly-websites/suggestions/6573329-support-for-node-gyp-in-nodejs-applications - MEMark

6

最近我成功地部署了一款基于Node.js的应用程序/Sails应用,作为一个依赖于Grunt并需要支持node-gyp的Azure Web应用程序。起初我在连续部署中遇到了让node-gyp运行而不包含node_modules文件夹的困难,但最终我通过一种你希望称之为"优雅解决方案"的方式成功了。

对我而言,必要的步骤是:

  1. Make sure you use a somewhat up to date version of Node and NPM (as far as Azure allows you to do so: . In my case I used node 5.4.0 and npm 3.3.12. Deploying on Azure there is two ways I know of to do this:

    • Application settings: WEBSITE_NODE_DEFAULT_VERSION 5.4.0 (or whatever)
    • Package.json file: Include the following:

      "engines": {    
          "node": "5.4.0",    
          "npm": "3.3.12"  
      },
      
  2. Change the settings in the config/env/production.js file to give grunt more time to uglify or whatever. The default value of 20s seems to be too low for a lot of applications out there, however there might be better ways to solve this: https://github.com/balderdashy/sails/issues/2691 I put:

    hookTimeout: 60000, // 60 seconds
    
  3. I used a .deployment and deploy.cmd / deploy.sh (depending on your system) file to customize the deployment on the Azure platform. The guide I used was: http://www.cptloadtest.com/2013/12/03/Git-And-Grunt-Deploy-To-Windows-Azure.aspx

    EDIT: looks like my original command to run Grunt from deploy.cmd is incorrect, I am not familiar with bash scripts, sorry. I ended up using the script from this question with some modifications: Deploying a NodeJS App to Azure Websites fails on installing NPM packages from pagages.json from deploy.cmd?
    Using this script my grunt task runs on deployment. Here are the modified parts of my script.
    deploy.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_modules\grunt-cli\bin\grunt"
    )
    
    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. I then ran into this error: ENOTSUP using Grunt which was thankfully recently solved :)
    All that was left for me to do was to change the for deploy.sh given syntax to work in my deploy.cmd. So before running grunt from deploy.cmd I included:

    echo 3. Update erroneous glob dependency in Grunt 
    pushd "%DEPLOYMENT_SOURCE%\node_modules\grunt"
    call :ExecuteCmd !NPM_CMD! install glob@^6.0.4 --save
    IF !ERRORLEVEL! NEQ 0 goto error
    popd
    
我希望这篇文章能对你们中的一些人有所帮助,尽管我知道,我遇到的一些问题可能已经可以通过使用最新版本的node和npm来解决。但由于Azure没有提供最新版本,因此这可能仍然对你们中的一些人有所帮助。 编辑: 关于:
  1. Node version choice:

    I tried to select the node version by only setting it in Package.json without changing the default settings in the Application settings (default version: 4.2.3) and I still got the following error:

    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:\home\site\wwwroot\iisnode.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:\home\site\wwwroot\node_modules\.staging\sails-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:\home\site\wwwroot\node_modules\fibers
    > node build.js || nodejs build.js
    
    
    D:\home\site\wwwroot\node_modules\fibers>if not defined npm_config_node_gyp (node "c:\Program Files (x86)\npm\3.3.12\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-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
    ..\src\fibers.cc : fatal error C1902: Program database manager mismatch; please check your installation [D:\home\site\wwwroot\node_modules\fibers\build\fibers.vcxproj]
    ..\src\coroutine.cc : fatal error C1902: Program database manager mismatch; please check your installation [D:\home\site\wwwroot\node_modules\fibers\build\fibers.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)\npm\3.3.12\node_modules\npm\node_modules\node-gyp\lib\build.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:\home\site\wwwroot\node_modules\fibers
    gyp ERR! node -v v4.2.3
    gyp ERR! node-gyp -v v3.0.3
    Build failed
    

    Like you can see it first states:

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

    according to the Package.json file.
    However, later on in the error message this seems to have changed:

    gyp ERR! node -v v4.2.3
    

    To me it is not obvious why this error occurs since the version in the Package.json file should be overwriting the default in the Application settings. So to be sure just set both settings to a high enough version (not sure when the node-gyp problem was solved, but 5.4.0 seems to be working fine!).


天啊...这给了我需要的答案。“使用Nuget”- 我不得不在最近的构建中将nuget从5更新到5.8...显然,我还需要“使用Node 10x”。令人惊奇的是,我需要对“默认”的安装进行许多小的更改,而这些更改本应该直接起作用。 - WernerCD

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接