Slava
Slava

Reputation: 6640

FAILED to deploy ASP.NET Core / Angular app to Azure from Github repository

I created a default project using dotnet new angular -o Homepage4.

I run this project dotnet run and it opens a default web page. Everything works.

I saved this project to GitHub repository.

Now I want my Azure site to be built from my GitHub repository.

In my Azure portal...

  1. Selected App Services
  2. Selected my app service (my web site)
  3. Selected Deployment options (classic)

enter image description here

  1. Selected GitHub as deployment option

enter image description here

  1. Select Homepage4 repository, master branch is selected automatically

enter image description here

  1. Clicked OK

And I got error

enter image description here

Clicked on that error, opens Deployment Details

enter image description here

I see the last command failed, clicked View Log

which opened a log console with the following content:

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"

I am not sure I understand what the problem is, can someone advise?

I will remind, its a default code generated when running dotnet new angular command. The code obviously is working when executed on a development machine by running dotnet run.

Thanks

UPDATE

I have changed npm version on Azure to 6.1.0

Trying to run the deployment again, but getting another fail:

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"

What is it this time?

Upvotes: 0

Views: 707

Answers (1)

Afzaal Ahmad Zeeshan
Afzaal Ahmad Zeeshan

Reputation: 15860

Your code works fine on development machine, because you are having npm 6.4, and on Azure it fails because you are having an older version of npm 1.4.28. The error is due to the npm library and requires you to update the npm library.

You need to enforce which npm and Node.js versions should be used for your app, you can add them to the package.json file and then retry the uploading. The default app that is created for you with dotnet new angular does not contain any engines property in the package.json file, which means the platform uses the default content. As the platforms available on your machine are, the Node.js and npm with 6.4, it works. On Azure, it goes to (~)1.4, and that causes the problem. Just solve the problem by adding the engines to your package.json, it goes in this area

"license": "MIT",
"engines": {
    "node": "8.1.4",
    "npm": "5.0.3"
},
"scripts": {

Then redeploy the app via GitHub, and it will work because this time you will be enforcing the platform to use these versions.

Please read a bit more on how the Node.js runtime is managed on Azure platform on this post: https://blogs.msdn.microsoft.com/azureossds/2016/04/20/nodejs-and-npm-versions-on-azure-app-services/

For a similar thread, to note the supported versions of Node.js runtime on Azure, please check, Which versions of node.js are available on Azure Web Sites?

Upvotes: 3

Related Questions