我需要在Production Server上安装Node.js来托管Angular 2吗? [英] Do I need to install Node.js on Production Server to host Angular 2?

查看:53
本文介绍了我需要在Production Server上安装Node.js来托管Angular 2吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在实时服务器(Windows 2008R2 IIS 7.5服务器)上部署我的第一个Angular 2应用程序

I am trying to deploy my 1st Angular 2 app on our live server (Windows 2008R2 IIS 7.5 server)

MVC部分运行正常.我可以看到登录用户名并显示MVC布局的框架.但这一直将我重定向到Error.cshtml.

The MVC part is running fine. I could see the login username and showing the frame of MVC layout. But it's redirecting me to the Error.cshtml all the time.

我试图打开DebugLog功能,并且收到以下错误日志.

I tried to turn on the DebugLog feature and I am getting the following error logs.

发生未处理的异常:无法启动Node进程.到 解决这个问题:

An unhandled exception has occurred: Failed to start Node process. To resolve this:.

[1]确保已安装Node.js,并且可以在其中之一找到它. PATH目录. 当前的PATH环境变量是:C:\ Windows \ system32; C:\ Windows; C:\ Windows \ System32 \ Wbem; C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \; C:\ Program Files \ Microsoft \ Web平台 安装程序\; C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \; C:\ Program Files \ dotnet \ ;; C:\ Program 文件\ dotnet \共享\ Microsoft.NETCore.App \ 1.1.1 确保Node可执行文件在这些目录之一中,或者更新您的PATH.

[1] Ensure that Node.js is installed and can be found in one of the PATH directories. Current PATH enviroment variable is: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\dotnet\;;C:\Program Files\dotnet\shared\Microsoft.NETCore.App\1.1.1 Make sure the Node executable is in one of those directories, or update your PATH.

[2]有关原因的更多详细信息,请参见InnerException.

[2] See the InnerException for further details of the cause.

它告诉我在生产服务器上安装Node.js.我可以将其安装在实时服务器上,但是不确定是否正确.

It's telling me to install Node.js on the Production Server. I can install it on the live server but I am not sure whether I am doing it right or not.

据我所知,所有类型的脚本文件都通过使用webpack编译为.js文件,为什么我们仍然需要在生产服务器上再次安装Node?

As far as I know, all type script files are compiled onto .js file by using webpack and why do we still need to install Node on the Production server again?

详细日志文件可以在此处查看

Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://prenrolments/  
info: Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware[3]
      HttpContext.User merged via AutomaticAuthentication from authenticationScheme: Cookie.
info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[1]
      Authorization was successful for user: ttcg.
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
      Executing action method PREnrolments.Controllers.HomeController.Index (PREnrolments) with arguments ((null)) - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor[1]
      Executing ViewResult, running view at path /Views/Home/Index.cshtml.
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
      Executed action PREnrolments.Controllers.HomeController.Index (PREnrolments) in 3883.5488ms
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[0]
      An unhandled exception has occurred: Failed to start Node process. To resolve this:.

[1] Ensure that Node.js is installed and can be found in one of the PATH directories.
    Current PATH enviroment variable is: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\dotnet\;;C:\Program Files\dotnet\shared\Microsoft.NETCore.App\1.1.1
    Make sure the Node executable is in one of those directories, or update your PATH.

[2] See the InnerException for further details of the cause.
System.InvalidOperationException: Failed to start Node process. To resolve this:.

[1] Ensure that Node.js is installed and can be found in one of the PATH directories.
    Current PATH enviroment variable is: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\dotnet\;;C:\Program Files\dotnet\shared\Microsoft.NETCore.App\1.1.1
    Make sure the Node executable is in one of those directories, or update your PATH.

[2] See the InnerException for further details of the cause. ---> System.ComponentModel.Win32Exception: The system cannot find the file specified
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.LaunchNodeProcess(ProcessStartInfo startInfo)
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.LaunchNodeProcess(ProcessStartInfo startInfo)
   at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance..ctor(String entryPointScript, String projectPath, String[] watchFileExtensions, String commandLineArguments, ILogger nodeOutputLogger, IDictionary`2 environmentVars, Int32 invocationTimeoutMilliseconds, Boolean launchWithDebugging, Int32 debuggingPort)
   at Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance..ctor(NodeServicesOptions options, Int32 port)
   at Microsoft.AspNetCore.NodeServices.HostingModels.NodeServicesOptionsExtensions.<>c__DisplayClass0_0.<UseHttpHosting>b__0()
   at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.GetOrCreateCurrentNodeInstance()
   at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.<InvokeExportWithPossibleRetryAsync>d__10`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.SpaServices.Prerendering.PrerenderTagHelper.<ProcessAsync>d__33.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.<RunAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at AspNetCore._Views_Home_Index_cshtml.<ExecuteAsync>d__35.MoveNext() in /Views/Home/Index.cshtml:line 2
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.<RenderPageAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.<RenderAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.<ExecuteAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.ViewResult.<ExecuteResultAsync>d__26.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeResultAsync>d__30.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResultFilterAsync>d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResultExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__6.MoveNext()
info: Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware[3]
      HttpContext.User merged via AutomaticAuthentication from authenticationScheme: Cookie.
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
      Executing action method PREnrolments.Controllers.HomeController.Error (PREnrolments) with arguments ((null)) - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor[1]
      Executing ViewResult, running view at path /Views/Shared/Error.cshtml.
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
      Executed action PREnrolments.Controllers.HomeController.Error (PREnrolments) in 724.6616ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 5619.0985ms 500 text/html; charset=utf-8

推荐答案

如果您使用"AspNetCoreSpaTemplates"创建了应用程序,在VS2017中,则默认情况下会添加"Microsoft.AspNEtCore.SpaServices"到您的项目,您应该在NuGet程序包列表下看到它(请参阅所附的屏幕截图).

If you have created your application using "AspNetCoreSpaTemplates" in VS2017 then by default it would add "Microsoft.AspNEtCore.SpaServices" to your project, you should see this under NuGet package list (please refer to the attached screenshot).

此"Microsoft.AspNEtCore.SpaServices"软件包包括"Microsoft.AspNetCore.NodeServices".依赖于服务器上的Node.js.

This "Microsoft.AspNEtCore.SpaServices" package includes "Microsoft.AspNetCore.NodeServices" which has dependency for Node.js on the server.

https://docs.microsoft.com/en-us/aspnet/core/client-side/spa-services

Microsoft.AspNEtCore.SpaServices用于服务器端预呈现.

Microsoft.AspNEtCore.SpaServices is used for server-side pre-rendering.

如果不需要此功能,可以从Nuget Package Manager选项中卸载Microsoft.AspNEtCore.SpaServices.

If you do not need this, you can uninstall Microsoft.AspNEtCore.SpaServices from Nuget Package Manager option.

卸载后,由于SPA服务在"Startup.cs"中引用,因此应该会出现2到3个构建错误. & "ViewImports.cshtml".注释或删除这些引用,并将您的代码发布到服务器.现在,它应该在服务器上没有Node.js的情况下也可以工作.

After you uninstall it you should get 2 to 3 build errors as the SPA services is referred in "Startup.cs" & "ViewImports.cshtml". Comment or delete those reference and publish your code to server. Now it should work without Node.js on the server.

这篇关于我需要在Production Server上安装Node.js来托管Angular 2吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆