我使用dotnet new angular -o Homepage4
创建了一个默认项目。
我运行这个项目dotnet run
,它会打开一个默认网页。一切正常。
我将此项目保存到GitHub存储库中。
现在,我希望从我的GitHub存储库构建Azure网站。
在我的Azure门户中...
我得到了错误
点击该错误,打开部署详细信息
我看到最后一个命令失败,单击了查看日志
它打开了一个日志控制台,其中包含以下内容:
Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling ASP.NET Core Web Application deployment.
Restoring packages for D:\home\site\repository\Homepage4.csproj...
Generating MSBuild file D:\home\site\repository\obj\Homepage4.csproj.nuget.g.props.
Generating MSBuild file D:\home\site\repository\obj\Homepage4.csproj.nuget.g.targets.
Restore completed in 3.2 sec for D:\home\site\repository\Homepage4.csproj.
Microsoft (R) Build Engine version 15.8.169+g1ccb72aefa for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 499.04 ms for D:\home\site\repository\Homepage4.csproj.
Homepage4 -> D:\home\site\repository\bin\Release\netcoreapp2.1\Homepage4.dll
Homepage4 -> D:\home\site\repository\bin\Release\netcoreapp2.1\Homepage4.Views.dll
EXEC : npm ERR! error : Method Not Allowed [D:\home\site\repository\Homepage4.csproj]
npm ERR! at errorResponse (D:\Program Files (x86)\npm\1.4.28\node_modules\npm\lib\cache\add-named.js:260:10)
npm ERR! at D:\Program Files (x86)\npm\1.4.28\node_modules\npm\lib\cache\add-named.js:203:12
npm ERR! at saved (D:\Program Files (x86)\npm\1.4.28\node_modules\npm\node_modules\npm-registry-client\lib\get.js:167:7)
npm ERR! at Object.oncomplete (fs.js:108:15)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR! <http://github.com/npm/npm/issues>
npm ERR! System Windows_NT 6.2.9200
npm ERR! command "node" "D:\\Program Files (x86)\\npm\\1.4.28\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! cwd D:\home\site\repository\ClientApp
npm ERR! node -v v0.10.40
npm ERR! npm -v 1.4.28
npm ERR! code E405
D:\home\site\repository\Homepage4.csproj(38,5): error MSB3073: The command "npm install" exited with code 1.
Failed exitCode=1, command=dotnet publish "D:\home\site\repository\Homepage4.csproj" --output "D:\local\Temp\8d645b0c2726c81" --configuration Release
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\78.11022.3613\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
我不确定我是什么问题,有人可以建议吗?
我会提醒一下,它是运行dotnet new angular
命令时生成的默认代码。通过运行dotnet run
在开发计算机上执行时,代码显然可以正常工作。
谢谢
更新
我已将Azure上的npm版本更改为6.1.0
尝试再次运行部署,但又失败了:
Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling ASP.NET Core Web Application deployment.
Restoring packages for D:\home\site\repository\Homepage.csproj...
Generating MSBuild file D:\home\site\repository\obj\Homepage.csproj.nuget.g.props.
Generating MSBuild file D:\home\site\repository\obj\Homepage.csproj.nuget.g.targets.
Restore completed in 3.43 sec for D:\home\site\repository\Homepage.csproj.
Microsoft (R) Build Engine version 15.8.169+g1ccb72aefa for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 354.75 ms for D:\home\site\repository\Homepage.csproj.
Homepage -> D:\home\site\repository\bin\Release\netcoreapp2.1\Homepage.dll
Homepage -> D:\home\site\repository\bin\Release\netcoreapp2.1\Homepage.Views.dll
D:\Program Files (x86)\npm\6.1.0\node_modules\npm\bin\npm-cli.js:79
let notifier = require('update-notifier')({pkg})
^^^^^^^^
SyntaxError: Unexpected identifier
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:935:3
D:\Program Files (x86)\npm\6.1.0\node_modules\npm\bin\npm-cli.js:79
let notifier = require('update-notifier')({pkg})
^^^^^^^^
SyntaxError: Unexpected identifier
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:935:3
D:\home\site\repository\Homepage.csproj(39,5): error MSB3073: The command "npm install" exited with code 8.
Failed exitCode=1, command=dotnet publish "D:\home\site\repository\Homepage.csproj" --output "D:\local\Temp\8d64a5971495781" --configuration Release
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\78.11022.3613\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
这是什么时间?
答案 0 :(得分:2)
您的代码在开发机上可以正常工作,因为您使用的是npm 6.4,而在Azure上则失败,因为您使用的是npm 1.4.28的旧版本。该错误是由于npm库引起的,需要您更新npm库。
您需要强制为您的应用程序使用哪个npm和Node.js版本,您可以将它们添加到package.json文件中,然后重试上载。使用dotnet new angular
为您创建的默认应用程序在package.json文件中不包含任何engines
属性,这意味着平台将使用默认内容。由于您机器上可用的平台是Node.js和6.4的npm,因此可以正常工作。在Azure上,它转到(〜)1.4,这会导致问题。只需将引擎添加到package.json中即可解决问题,它就在该区域
"license": "MIT",
"engines": {
"node": "8.1.4",
"npm": "5.0.3"
},
"scripts": {
然后通过GitHub重新部署该应用程序,它将起作用,因为这次您将强制平台使用这些版本。
有关这篇文章,请阅读更多有关如何在Azure平台上管理Node.js运行时的信息:https://blogs.msdn.microsoft.com/azureossds/2016/04/20/nodejs-and-npm-versions-on-azure-app-services/
对于类似的线程,要注意Azure上支持的Node.js运行时版本,请检查Which versions of node.js are available on Azure Web Sites?