dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.28k stars 9.96k forks source link

Can't debug SpaProxy on Linux Docker container #41093

Open JoshClose opened 2 years ago

JoshClose commented 2 years ago

Is there an existing issue for this?

Describe the bug

I followed the instructions here. https://docs.microsoft.com/en-us/visualstudio/containers/edit-and-refresh?view=vs-2022

I'm using a Linux Docker container.

When debugging the app, I get this error.

[17:05:38+00:00 INF 001 Microsoft.Hosting.Lifetime] Now listening on: https://[::]:443
[17:05:38+00:00 INF 001 Microsoft.Hosting.Lifetime] Now listening on: http://[::]:80
[17:05:38+00:00 INF 001 Microsoft.Hosting.Lifetime] Application started. Press Ctrl+C to shut down.
[17:05:38+00:00 INF 001 Microsoft.Hosting.Lifetime] Hosting environment: Development
[17:05:38+00:00 INF 001 Microsoft.Hosting.Lifetime] Content root path: /app/
[17:05:41+00:00 INF 012 Microsoft.AspNetCore.Hosting.Diagnostics] Request starting HTTP/2 GET https://localhost:49173/ - -
[17:05:41+00:00 INF 010 Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager] No SPA development server running at https://localhost:44476 found.
[17:05:41+00:00 ERR 010 Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager] Failed to launch the SPA development server 'npm start'.
System.ComponentModel.Win32Exception (2): An error occurred trying to start process '/usr/bin/npm' with working directory '/app/bin/Debug/net6.0/C:\Users\Me\Projects\MyProject\src\MyProject\ClientApp\'. No such file or directory
   at System.Diagnostics.Process.ForkAndExecProcess(ProcessStartInfo startInfo, String resolvedFilename, String[] argv, String[] envp, String cwd, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager.LaunchDevelopmentProxy()
[17:05:41+00:00 ERR 010 Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager] Couldn't start the SPA development server with command 'npm start'.

I found that there is a spa.proxy.json file that is generated that contains the wrong information.

{
"SpaProxyServer": {
"ServerUrl": "https://localhost:44476",
"LaunchCommand": "npm start",
"WorkingDirectory": "C:\\Users\\Me\\Projects\\MyProject\\src\\MyProject\\ClientApp\\",
"MaxTimeoutInSeconds": "120"
}
}

Expected Behavior

When running in a Linux container the spa.proxy.json file should contain the correct path for the application inside the container, not the local host system.

Steps To Reproduce

https://docs.microsoft.com/en-us/visualstudio/containers/edit-and-refresh?view=vs-2022

Exceptions (if any)

[17:05:38+00:00 INF 001 Microsoft.Hosting.Lifetime] Now listening on: https://[::]:443
[17:05:38+00:00 INF 001 Microsoft.Hosting.Lifetime] Now listening on: http://[::]:80
[17:05:38+00:00 INF 001 Microsoft.Hosting.Lifetime] Application started. Press Ctrl+C to shut down.
[17:05:38+00:00 INF 001 Microsoft.Hosting.Lifetime] Hosting environment: Development
[17:05:38+00:00 INF 001 Microsoft.Hosting.Lifetime] Content root path: /app/
[17:05:41+00:00 INF 012 Microsoft.AspNetCore.Hosting.Diagnostics] Request starting HTTP/2 GET https://localhost:49173/ - -
[17:05:41+00:00 INF 010 Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager] No SPA development server running at https://localhost:44476 found.
[17:05:41+00:00 ERR 010 Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager] Failed to launch the SPA development server 'npm start'.
System.ComponentModel.Win32Exception (2): An error occurred trying to start process '/usr/bin/npm' with working directory '/app/bin/Debug/net6.0/C:\Users\Me\Projects\MyProject\src\MyProject\ClientApp\'. No such file or directory
   at System.Diagnostics.Process.ForkAndExecProcess(ProcessStartInfo startInfo, String resolvedFilename, String[] argv, String[] envp, String cwd, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager.LaunchDevelopmentProxy()
[17:05:41+00:00 ERR 010 Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager] Couldn't start the SPA development server with command 'npm start'.

.NET Version

6.0

Anything else?

Visual Studio 2022

javiercn commented 2 years ago

@JoshClose thanks for contacting us.

For docker scenarios it is recommended that you run the .NET app separately from the SPA frontend during development.

You can disable the automatic SPA launch from the .NET app and run it inside the container and then start the SPA frontend manually with npm run start in the host during development.

JoshClose commented 2 years ago

That's what I've been doing as a workaround.

I posted the wrong link above. The correct link is https://docs.microsoft.com/en-us/visualstudio/containers/container-tools-react?view=vs-2022 Maybe the debug section here should be changed to reflect your recommendation.

mkArtakMSFT commented 2 years ago

Thanks for clarification, @JoshClose. @javiercn parking this on our backlog to update the docs with your suggestion above.

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

Blueve commented 2 years ago

I encoutner the same issue. This is obviously a bug and hoping we can have a workaround in doc at least : )

https://github.com/dotnet/aspnetcore/blob/3ea008c80d5cc63de7f90ddfd6823b7b006251ff/src/Middleware/Spa/SpaProxy/src/SpaProxyLaunchManager.cs#L188

https://github.com/dotnet/aspnetcore/blob/6bc4b79f4ee7af00edcbb435e5ee4c1de349a110/src/Middleware/Spa/SpaProxy/src/build/Microsoft.AspNetCore.SpaProxy.targets#L14

ghost commented 1 year ago

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

ghost commented 11 months ago

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.