在 Azure 应用服务上安装 npm 包时出错

Posted

技术标签:

【中文标题】在 Azure 应用服务上安装 npm 包时出错【英文标题】:Error installing npm package on Azure app service 【发布时间】:2018-05-25 08:28:09 【问题描述】:

能够在 Linux 和 Windows 7 上使用 npm install 成功构建 better-sqlite3integer@1.0.1 没有问题。但是在 Azure 上有问题。出现以下错误:

> npm install integer -dd
�[37;40mnpm info it worked if it ends with ok
�[37;40mnpm �[34;40mverb cli [ 'D:\\Program Files (x86)\\nodejs\\8.9.0\\node.exe',
�[37;40mnpm �[34;40mverb cli   'D:\\Program Files (x86)\\npm\\5.5.1\\node_modules\\npm\\bin\\npm-cli.js',
�[37;40mnpm �[34;40mverb cli   'install',
�[37;40mnpm �[34;40mverb cli   'integer',
�[37;40mnpm �[34;40mverb cli   '-dd' ]
�[37;40mnpm info using npm@5.5.1
�[37;40mnpm info using node@v8.9.0
�[37;40mnpm �[34;40mverb npm-session 8016124db333a5c2
�[37;40mnpm �[32;40mhttp fetch GET 304 https://registry.npmjs.org/integer 283ms (from cache)
�[37;40mnpm �[34;40mverb correctMkdir D:\local\Temp\monacositeextension\temp\_locks correctMkdir not in flight; initializing
�[37;40mnpm �[34;40mverb lock using D:\local\Temp\monacositeextension\temp\_locks\staging-7ccd117e5dc1e199.lock for D:\home\site\wwwroot\node_modules\.staging
�[37;40mnpm info lifecycle to-descriptor@1.0.1~preuninstall: to-descriptor@1.0.1
�[37;40mnpm info lifecycle to-descriptor@1.0.1~uninstall: to-descriptor@1.0.1
�[37;40mnpm �[34;40mverb unbuild rmStuff to-descriptor@1.0.1 from D:\home\site\wwwroot\node_modules
�[37;40mnpm info lifecycle to-descriptor@1.0.1~postuninstall: to-descriptor@1.0.1
�[37;40mnpm info lifecycle lzz-gyp@0.4.2~preuninstall: lzz-gyp@0.4.2
�[37;40mnpm info lifecycle lzz-gyp@0.4.2~uninstall: lzz-gyp@0.4.2
�[37;40mnpm �[34;40mverb unbuild rmStuff lzz-gyp@0.4.2 from D:\home\site\wwwroot\node_modules
�[37;40mnpm info lifecycle lzz-gyp@0.4.2~postuninstall: lzz-gyp@0.4.2
�[37;40mnpm info lifecycle integer@1.0.1~preinstall: integer@1.0.1
�[37;40mnpm info linkStuff integer@1.0.1
�[37;40mnpm �[34;40mverb linkBins integer@1.0.1
�[37;40mnpm �[34;40mverb linkMans integer@1.0.1
�[37;40mnpm info lifecycle integer@1.0.1~install: integer@1.0.1
gyp info it worked if it ends with ok
gyp verb cli [ 'D:\\Program Files (x86)\\nodejs\\8.9.0\\node.exe',
gyp verb cli   'D:\\Program Files (x86)\\npm\\5.5.1\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli   'rebuild' ]
gyp info using node-gyp@3.6.2
gyp info using node@8.9.0 | win32 | ia32
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed     at getNotFoundError (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\which\which.js:80:29)
gyp verb `which` failed     at D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\which\which.js:89:16
gyp verb `which` failed     at D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\which\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\which\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:152:21)
gyp verb `which` failed  python2  Error: not found: python2
gyp verb `which` failed     at getNotFoundError (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\which\which.js:80:29)
gyp verb `which` failed     at D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\which\which.js:89:16
gyp verb `which` failed     at D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\which\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\which\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:152:21)
gyp verb `which` failed   stack: 'Error: not found: python2\n    at getNotFoundError (D:\\Program Files (x86)\\npm\\5.5.1\\node_modules\\npm\\node_modules\\which\\which.js:13:12)\n    at F (D:\\Program Files (x86)\\npm\\5.5.1\\node_modules\\npm\\node_modules\\which\\which.js:68:19)\n    at E (D:\\Program Files (x86)\\npm\\5.5.1\\node_modules\\npm\\node_modules\\which\\which.js:80:29)\n    at D:\\Program Files (x86)\\npm\\5.5.1\\node_modules\\npm\\node_modules\\which\\which.js:89:16\n    at D:\\Program Files (x86)\\npm\\5.5.1\\node_modules\\npm\\node_modules\\which\\node_modules\\isexe\\index.js:42:5\n    at D:\\Program Files (x86)\\npm\\5.5.1\\node_modules\\npm\\node_modules\\which\\node_modules\\isexe\\windows.js:36:5\n    at FSReqWrap.oncomplete (fs.js:152:21)',
gyp verb `which` failed   code: 'ENOENT' 
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python D:\Python27\python.EXE

> integer@1.0.1 install D:\home\site\wwwroot\node_modules\integer
> node tools/install


D:\home\site\wwwroot\node_modules\integer>if not defined npm_config_node_gyp (node "D:\Program Files (x86)\npm\5.5.1\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild ) 
gyp verb check python version `D:\Python27\python.EXE -c "import platform; print(platform.python_version());"` returned: "2.7.8\r\n"
gyp verb get node dir no --target version specified, falling back to host node version: 8.9.0
gyp verb command install [ '8.9.0' ]
gyp verb install input version string "8.9.0"
gyp verb install installing version: 8.9.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 8.9.0
gyp verb build dir attempting to create "build" dir: D:\home\site\wwwroot\node_modules\integer\build
gyp verb build dir "build" dir needed to be created? D:\home\site\wwwroot\node_modules\integer\build
gyp verb Not using VS2017: Could not use PowerShell to find VS2017
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: D:\home\site\wwwroot\node_modules\integer\build\config.gypi
gyp verb config.gypi checking for gypi file: D:\home\site\wwwroot\node_modules\integer\config.gypi
gyp verb common.gypi checking for gypi file: D:\home\site\wwwroot\node_modules\integer\common.gypi
gyp verb gyp gyp format was not specified; forcing "msvs"
gyp info spawn D:\Python27\python.EXE
gyp info spawn args [ 'D:\\Program Files (x86)\\npm\\5.5.1\\node_modules\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-G',
gyp info spawn args   'msvs_version=auto',
gyp info spawn args   '-I',
gyp info spawn args   'D:\\home\\site\\wwwroot\\node_modules\\integer\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'D:\\Program Files (x86)\\npm\\5.5.1\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'D:\\local\\UserProfile\\.node-gyp\\8.9.0\\include\\node\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=D:\\local\\UserProfile\\.node-gyp\\8.9.0',
gyp info spawn args   '-Dnode_gyp_dir=D:\\Program Files (x86)\\npm\\5.5.1\\node_modules\\npm\\node_modules\\node-gyp',
gyp info spawn args   '-Dnode_lib_file=D:\\local\\UserProfile\\.node-gyp\\8.9.0\\<(target_arch)\\node.lib',
gyp info spawn args   '-Dmodule_root_dir=D:\\home\\site\\wwwroot\\node_modules\\integer',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'D:\\home\\site\\wwwroot\\node_modules\\integer\\build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp verb command build []
gyp verb build type Release
gyp verb architecture ia32
gyp verb node dev dir D:\local\UserProfile\.node-gyp\8.9.0
gyp verb found first Solution file build/binding.sln
gyp verb could not find "msbuild.exe" in PATH - finding location in registry 
gyp info spawn D:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe
gyp info spawn args [ 'build/binding.sln',
gyp info spawn args   '/nologo',
gyp info spawn args   '/p:Configuration=Release;Platform=Win32' ]
gyp ERR! build error 
gyp ERR! stack Error: `D:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\node-gyp\lib\build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 6.2.9200
gyp ERR! command "D:\\Program Files (x86)\\nodejs\\8.9.0\\node.exe" "D:\\Program Files (x86)\\npm\\5.5.1\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\home\site\wwwroot\node_modules\integer
gyp ERR! node -v v8.9.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 
�[37;40mnpm �[34;40mverb lifecycle integer@1.0.1~install: unsafe-perm in lifecycle true
�[37;40mnpm �[34;40mverb lifecycle integer@1.0.1~install: PATH: D:\Program Files (x86)\npm\5.5.1\node_modules\npm\bin\node-gyp-bin;D:\home\site\wwwroot\node_modules\integer\node_modules\.bin;D:\home\site\wwwroot\node_modules\.bin;D:\Program Files (x86)\nodejs\8.9.0;D:\Program Files (x86)\Git\bin;D:\Program Files (x86)\nodejs\8.9.0;D:\Windows\system32;D:\Windows;D:\Windows\System32\Wbem;D:\Windows\System32\WindowsPowerShell\v1.0\;D:\Program Files (x86)\Git\cmd;D:\Program Files\Microsoft Network Monitor 3\;D:\Program Files (x86)\dotnet;D:\Program Files (x86)\php\v5.6;D:\Python27;
�[37;40mnpm �[34;40mverb lifecycle integer@1.0.1~install: CWD: D:\home\site\wwwroot\node_modules\integer
�[37;40mnpm info lifecycle integer@1.0.1~install: Failed to exec install script
�[37;40mnpm �[34;40mverb unlock done using D:\local\Temp\monacositeextension\temp\_locks\staging-7ccd117e5dc1e199.lock for D:\home\site\wwwroot\node_modules\.staging
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 12/11/2017 6:11:30 PM.
Project "D:\home\site\wwwroot\node_modules\integer\build\binding.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Release|Win32".
Project "D:\home\site\wwwroot\node_modules\integer\build\binding.sln" (1) is building "D:\home\site\wwwroot\node_modules\integer\build\integer.vcxproj" (2) on node 1 (default targets).
D:\home\site\wwwroot\node_modules\integer\build\integer.vcxproj(20,3): error MSB4019: The imported project "D:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
Done Building Project "D:\home\site\wwwroot\node_modules\integer\build\integer.vcxproj" (default targets) -- FAILED.
Done Building Project "D:\home\site\wwwroot\node_modules\integer\build\binding.sln" (default targets) -- FAILED.

Build FAILED.

"D:\home\site\wwwroot\node_modules\integer\build\binding.sln" (default target) (1) ->
"D:\home\site\wwwroot\node_modules\integer\build\integer.vcxproj" (default target) (2) ->
  D:\home\site\wwwroot\node_modules\integer\build\integer.vcxproj(20,3): error MSB4019: The imported project "D:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.17
�[37;40mnpm �[34;40mverb stack Error: integer@1.0.1 install: `node tools/install`
�[37;40mnpm �[34;40mverb stack Exit status 1
�[37;40mnpm �[34;40mverb stack     at EventEmitter.<anonymous> (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\npm-lifecycle\index.js:280:16)
�[37;40mnpm �[34;40mverb stack     at emitTwo (events.js:126:13)
�[37;40mnpm �[34;40mverb stack     at EventEmitter.emit (events.js:214:7)
�[37;40mnpm �[34;40mverb stack     at ChildProcess.<anonymous> (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
�[37;40mnpm �[34;40mverb stack     at emitTwo (events.js:126:13)
�[37;40mnpm �[34;40mverb stack     at ChildProcess.emit (events.js:214:7)
�[37;40mnpm �[34;40mverb stack     at maybeClose (internal/child_process.js:925:16)
�[37;40mnpm �[34;40mverb stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
�[37;40mnpm �[34;40mverb stack From previous event:
�[37;40mnpm �[34;40mverb stack     at runAction (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\lib\install\actions.js:74:13)
�[37;40mnpm �[34;40mverb stack     at actions.(anonymous function) (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\lib\install\actions.js:50:17)
�[37;40mnpm �[34;40mverb stack     at execAction (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\lib\install\actions.js:198:18)
�[37;40mnpm �[34;40mverb stack     at runCallback (timers.js:789:20)
�[37;40mnpm �[34;40mverb stack     at tryOnImmediate (timers.js:751:5)
�[37;40mnpm �[34;40mverb stack     at processImmediate [as _immediateCallback] (timers.js:722:5)
�[37;40mnpm �[34;40mverb stack From previous event:
�[37;40mnpm �[34;40mverb stack     at withInit (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\lib\install\actions.js:166:15)
�[37;40mnpm �[34;40mverb stack From previous event:
�[37;40mnpm �[34;40mverb stack     at withInit (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\lib\install\actions.js:182:13)
�[37;40mnpm �[34;40mverb stack     at runSerial (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\lib\install\actions.js:165:10)
�[37;40mnpm �[34;40mverb stack     at doSerial (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\lib\install\actions.js:146:3)
�[37;40mnpm �[34;40mverb stack     at Array.<anonymous> (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\slide\lib\bind-actor.js:15:8)
�[37;40mnpm �[34;40mverb stack     at LOOP (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\slide\lib\chain.js:15:14)
�[37;40mnpm �[34;40mverb stack     at D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\slide\lib\chain.js:18:7
�[37;40mnpm �[34;40mverb stack     at doParallel (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\lib\install\actions.js:130:30)
�[37;40mnpm �[34;40mverb stack     at Array.<anonymous> (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\slide\lib\bind-actor.js:15:8)
�[37;40mnpm �[34;40mverb stack     at LOOP (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\slide\lib\chain.js:15:14)
�[37;40mnpm �[34;40mverb stack     at D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\slide\lib\chain.js:18:7
�[37;40mnpm �[34;40mverb stack     at runSerial (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\lib\install\actions.js:164:30)
�[37;40mnpm �[34;40mverb stack     at doSerial (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\lib\install\actions.js:146:3)
�[37;40mnpm �[34;40mverb stack     at Array.<anonymous> (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\slide\lib\bind-actor.js:15:8)
�[37;40mnpm �[34;40mverb stack     at LOOP (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\slide\lib\chain.js:15:14)
�[37;40mnpm �[34;40mverb stack     at D:\Program Files (x86)\npm\5.5.1\node_modules\npm\node_modules\slide\lib\chain.js:18:7
�[37;40mnpm �[34;40mverb stack     at withInit.nodeify (D:\Program Files (x86)\npm\5.5.1\node_modules\npm\lib\install\actions.js:170:5)
�[37;40mnpm �[34;40mverb pkgid integer@1.0.1
�[37;40mnpm �[34;40mverb cwd D:\home\site\wwwroot
�[37;40mnpm �[34;40mverb Windows_NT 6.2.9200
�[37;40mnpm �[34;40mverb argv "D:\\Program Files (x86)\\nodejs\\8.9.0\\node.exe" "D:\\Program Files (x86)\\npm\\5.5.1\\node_modules\\npm\\bin\\npm-cli.js" "install" "integer" "-dd"
�[37;40mnpm �[34;40mverb node v8.9.0
�[37;40mnpm �[34;40mverb npm  v5.5.1
�[37;40mnpm �[31;40mERR! code ELIFECYCLE
�[37;40mnpm �[31;40mERR! errno 1
�[37;40mnpm �[31;40mERR! integer@1.0.1 install: `node tools/install`
�[37;40mnpm �[31;40mERR! Exit status 1
�[37;40mnpm �[31;40mERR! 
�[37;40mnpm �[31;40mERR! Failed at the integer@1.0.1 install script.
�[37;40mnpm �[31;40mERR! This is probably not a problem with npm. There is likely additional logging output above.
�[37;40mnpm �[34;40mverb exit [ 1, true ]

�[37;40mnpm �[31;40mERR! A complete log of this run can be found in:
�[37;40mnpm �[31;40mERR!     D:\local\Temp\monacositeextension\temp\_logs\2017-12-11T18_11_32_508Z-debug.log

问题可能是什么?怎么解决?需要在那里安装一些东西或升级版本吗?日志文件link。

【问题讨论】:

【参考方案1】:

Python2 和 D:\Microsoft.Cpp.Default.props 的问题已解决。 Kudu 中的步骤(在应用服务编辑器中不起作用):

    npm config set msvs_version 2013 npm config set python D:\Python27\python.exe SET VCTargetsPath=D:\Program Files(x86)\MSBuild\Microsoft.Cpp\v4.0\V140

之后又出现了一个错误:

d:\local\userprofile.node-gyp\8.9.0\include\node\v8.h(21): 致命 错误 C1083:无法打开包含文件:“内存”:没有这样的文件或 目录 [D:\home\site\wwwroot\node_modules\integer\build\integer.vcxproj

MS 支持人员表示,安装需要 node-gyp 构建的 nodejs 模块存在一些已知问题,目前唯一的 workaround 是在安装了所有本机模块先决条件的本地 Windows 机器上运行 npm install。然后,将创建的 node_modules 文件夹作为应用程序的一部分部署到 Azure 应用服务(通过 Git 或 FTP)。

更多信息请参考:Installing native nodejs modules on Azure App Services during Git Deployment

MS 的未来说明:

我们的产品组已经修复了一些与 node-gyp 相关的已知问题 是他们正在调查的其他夫妇。 此工作项目在我们的优先级列表中,您应该会在以后的版本中看到对 node-gyp 的更好支持。

【讨论】:

【参考方案2】:

msbuild 由于缺少依赖项而失败.. 一些 C++ 运行时的东西。只需将其包装在 Dockerfile 中并将其放到 App Service Linux 上,这是一个简单且易于维护的解决方案 - https://azure.microsoft.com/en-us/services/app-service/containers/

如果您真的想“就地”解决这个问题,您可能还想查看this answer。这是 Azure 应用服务(Windows 工作者)的正确 VCTargetsPath -

D:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140

** 请注意,这可能根本不起作用,因为它只是在黑暗中拍摄,而不是彻底分析的结果。

【讨论】:

这对我来说需要很多时间。现有的 Node.JS 应用程序是否有更简单的解决方案? 是的,只需从另一个 Windows 机器中复制 node_modules/ 二进制文件即可。 是否可以将缺少的 C++ 依赖项安装到现有应用程序而无需从另一个 Windows 机器复制? 不,您的应用是沙盒的,没有提升的权限。

以上是关于在 Azure 应用服务上安装 npm 包时出错的主要内容,如果未能解决你的问题,请参考以下文章

使用 Azure Pipelines 上传 python 包时出错

读取包时出错:graceful-fs\package.json

安装 NPM 导航依赖包安装时出错

尝试在 Windows 上安装 NPM 包时遇到证书错误。我正在使用节点 v10.9.0

在 Windows 上安装 Rmpi​​ 包时出错

React-navigation- dependencies (安装 NPM 导航依赖包安装时出错)