dotnet / dotnet/aspnetcore

Can't debug SpaProxy on Linux Docker container

Open
#41,093 7 comments 8 reactions 0 assignees View on GitHub
area-ui-rendering bug docker feature-spa
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### 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.

```json
{
"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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.