Debugging SPFx Solutions in Github Codespaces #7758
Replies: 17 comments 3 replies
-
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible. |
Beta Was this translation helpful? Give feedback.
-
Hi @shurick81 - in 1.14 beta (that should be released soon) we introduced new configuration called |
Beta Was this translation helpful? Give feedback.
-
When you open an SPFx project in Codespaces, you are getting a new VM based on the default Linux container (unless you have configured .devcontainers). Regardless, because this is a new "machine," you have to generate the developer certificate, download it to your local machine and install it in the Certificate store. If not, localhost will not deliver the manifest.js file to your browser and you get the initial errors you are seeing. (Error loading manifest.js) |
Beta Was this translation helpful? Give feedback.
-
@DonKirkham, thanks, but as I noted above, getting manifest.js was not prevented by certificate, but only by the host name configuration. I'm not sure how it was in earlier times of Codespaces, but right now its proxy is exposing SSL with it's own certificate, so adding the certificate from container to the client device should not be necessary. |
Beta Was this translation helpful? Give feedback.
-
I have run a few tests with a new project, scaffolded with SPFx 1.14.0 that was released just today :). I tested running in Github Codespaces a few different configurations in /config/serve.json
This worked just fine in a local container or in the Visual Studio Code Remote Container but when I try to use it with Github Codespaces, I still get this behavior: I can get /temp/manifests.js file in the browser on https://shurick81-alexsapozhkov-codespaces-demo-01-96j5q5x6h7xgq-4321.githubpreview.dev/temp/manifests.js but it is full of "https://localhost" references in the content: And the hosted workbench throws the error, probably because of this localhost reference: I noticed additional issue after that. If I stop This additional problem is only solved after I rebuild the whole container in Github Codespaces.
Behavior is the same as in case 1.
Behavior is the same as in case 1. Additional infoHere's the command that I used for scaffolding:
This is the repo: |
Beta Was this translation helpful? Give feedback.
-
Do I get it right that in order to make Github Codespaces web site |
Beta Was this translation helpful? Give feedback.
-
@shurick81 - Can you please try to
gulp trust-dev-cert
cp ~/.gcb-serve-data/gcb-serve.cer ./spfx-dev-cert.cer
cp ~/.gcb-serve-data/gcb-serve.cer ./spfx-dev-cert.pem |
Beta Was this translation helpful? Give feedback.
-
Ok, I run "View: Show Remote Explorer" in VS code terminal I run Where should I see that message that port 4321 is forwarded? I can see this if I switch tab to "PORTS": I can see that the manifests file is served: What certificates on what local machine? On my local machine when I access manifests, they are served behind the application proxy that is using a publicly valid certificate: |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
The picture you are showing with ports @anoopt, it is not from Codespaces, it is from remote containers, right? In this case yes it will be 127.0.0.1 on your machine and it will be exposed via the same SSL certificate that you set up in browser. Github Codes Codespaces is different in this sense: it is exposed on the remote host. That is why it is important that manifests refer to the remote host name too. You can see in my previous comments that probably the issue is that even though all assets are hosted on the shurick81-alexsapozhkov-codespaces-demo-01-96j5q5x6h7xgq-4321.githubpreview.dev host name, manifests are referring to localhost. As a result, the browser can reach manifests file without issues but then browser executes it and trying to reach resources on localhost, which will never work for Github Codespaces. |
Beta Was this translation helpful? Give feedback.
-
Thanks @shurick81 - the ports are from codespaces as you can see it under What I have noticed is when I have the So, if you create new repo without the Not sure if the image |
Beta Was this translation helpful? Give feedback.
-
Thanks @anoopt, you were totally right, now it is working in codespaces in VS and everything exposed on 127.0.0.1. I just copied the same code but removed .devcontainer directory and then created a codespace "adhoc": https://github.com/alexsapozhkov/codespaces-test-03. Here's the result: And this is considering that I don't even have Docker running on this machine, just VS and browser. The container is completely remote but somehow it is exposed on the 127.0.0.1... How will I sleep now without understanding how this exposure is controlled... |
Beta Was this translation helpful? Give feedback.
-
I digged a bit deeper now and the only change I needed to do in order to make the port available on the localhost is this: alexsapozhkov/codespaces-test-04@7e63720 |
Beta Was this translation helpful? Give feedback.
-
I think we could close this issue since debugging is now working with Codespaces. However, then we need to open a new issue regarding debugging without Visual Studio installed, with just browser. When I use just browser, without Visual Studio, it is of course not possible to expose the container port on the localhost, so the port is forwarded to In such scenario, gulp serve should generate assets that refer to the remote host name in *.githubpreview.dev space. But that should be probably registered as a separate issue? |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, First of all: thanks for all the investigation, really interesting walkthrough! I've started to have a look at running a forked repo with GitHub Codespaces to test the code and encountered some issues... First one is when using Codespaces app (provided by VS Code but as a separate instance). I got the same forwared URL as mentioned above ("reimagined-spork-blablabla-4321.app.github.dev" here). devcontainer.json {
"name": "SPFx",
"image": "m365pnp/spfx:1.17.3",
// Set *default* container specific settings.json values on container create.
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint",
"ms-vscode.vscode-typescript-tslint-plugin"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [4321, 5432, 35729],
"portsAttributes": {
"4321": {
"protocol": "https",
"label": "Manifest",
"onAutoForward": "silent",
"requireLocalPort": true
},
"35729": {
"protocol": "https",
"label": "LiveReload",
"onAutoForward": "silent",
"requireLocalPort": true
}
},
"postCreateCommand": "bash .devcontainer/spfx-startup.sh",
"remoteUser": "node"
} serve.json has the same config as declared here. Ports are declared like this: I've run the So I've tried directly from VS Code with which I have forwarded URL to localhost: But now I got a certificate issue: devcontainer.json {
"name": "SPFx",
"image": "m365pnp/spfx:1.17.3",
// Set *default* container specific settings.json values on container create.
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint",
"ms-vscode.vscode-typescript-tslint-plugin"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [4321, 5432, 35729],
"portsAttributes": {
// "4321": {
// "protocol": "https",
// "label": "Manifest",
// "onAutoForward": "silent",
// "requireLocalPort": true
// },
"35729": {
"protocol": "https",
"label": "LiveReload",
"onAutoForward": "silent",
"requireLocalPort": true
}
},
"postCreateCommand": "bash .devcontainer/spfx-startup.sh",
"remoteUser": "node"
} I tried suggestion above (generating the .cer file, downloading it locally and installing it on my machine) without success. Even if what suggested @anoopt above (starting from a fresh repo then generate its Codespaces) works, my concern is regarding the use case when you want to test someone's branch / repo quickly without having to install the prerequisites. We should be able to generate a Codespace from a repo and simply launch a local browser. Does someone figured out with a similar use case or am I doing this wrong? |
Beta Was this translation helpful? Give feedback.
-
@michaelmaillot, are you trying to use Codespaces from Visual Studio or from a web browser? I only managed to get it working from Visual Studio |
Beta Was this translation helpful? Give feedback.
-
I don't know why it did not work with installing certificate in your system: the error looks exactly like the certificate is not trusted. If you want, we could try troubleshoot this together. But in general, I think you are totally right: we need this use case just available from the SPFx tool belt, it should not require these strange troubleshooting steps when one just wants to share your commit with other people in their team. |
Beta Was this translation helpful? Give feedback.
-
What type of issue is this?
Question
What SharePoint development model, framework, SDK or API is this about?
💥 SharePoint Framework
Target SharePoint environment
SharePoint Online
What browser(s) / client(s) have you tested
Additional environment details
Issue description
Would it be possible to debug SPFx solutions using Github workspaces?
When I just try to run the solution as is, I get an error in the hosted workbench:
https://steria.sharepoint.com/_layouts/15/workbench.aspx?debug=true&noredir=true&debugManifestsFile=https://shurick81-alexsapozhkov-codespaces-demo-00-77p5r5x73xrpw-4321.githubpreview.dev/temp/manifests.js
I try to dig deeper and checking https://shurick81-alexsapozhkov-codespaces-demo-00-77p5r5x73xrpw-4321.githubpreview.dev/temp/manifests.js in the browser, I'm getting a Bad Gateway error:
Then I try to fix the latter one and do the following changes (that helps for running SPFx gulp serve in containers: https://github.com/pnp/docker-spfx#known-issues):
node_modules\@microsoft\spfx-heft-plugins\lib\plugins\webpackConfigurationPlugin\WebpackConfigurationGenerator.js:393
to:
0.0.0.0
, by modifying the./config/serve.json
file in your SharePoint Framework project to:I get the response when I request js file then:
However, when I try to run the hosted workbench, I get new issues:
When I look into developer tools in the browser, I can see that the browser is getting proper response from https://shurick81-alexsapozhkov-codespaces-demo-00-77p5r5x73xrpw-4321.githubpreview.dev/temp/manifests.js but then it is trying to access resources from https://localhost:4321/temp/manifests.js and of course fails:
I might guess that the reason is that the file https://shurick81-alexsapozhkov-codespaces-demo-00-77p5r5x73xrpw-4321.githubpreview.dev/temp/manifests.js actually contains a lot of references on the localhost:
Beta Was this translation helpful? Give feedback.
All reactions