pnp/docker-spfx

Running Docker SPFx

Mike-tech opened this issue · 18 comments

Hi Waldek

I've used SPFx in the past for many implementations on full Vm. Now I'm trying to use Docker with SPFx for the first time because it make sense. But i just can't get this to work.

First i had issue with the install of yo @microsoft/sharepoint, but found the workaround you mentioned on here: #19.

That seems to now install as expected. In my case i'm installing ListView Command Set. When i then run gulp serve, after entering my list url in the serve.json in config, i get below error when the package is trying to run:

image

Then when i paste the url in the browser in my host machine, i get the usual Allow debug scripts, when i click Load debug scripts, i then get this below:

image

I've tried to run the gulp trust-dev-cert in the docker host, but made no difference. What am i doing wrong or is this a wider issue? I've also replicate this on another separate machine and tried few older images with the same error.

My knowledge on docker is very basic so let me know if there are steps i'm missing. But looking at the video you did back in 2018 on this topic, i can't see anything different to what i'm doing.

Thanks in advance

On which OS are you using Docker?

Windows 10 Pro

And which version of the docker image are you using?

Using the latest image which is 1.9.1. I've also tried 1.8.0 or 1.7.1 and I believe it was the same outcome.

Are you getting errors only when working with List View Command Sets or are you seeing the same error no matter which component you build?

Seems to be the same when trying to create a web part too:

image

I'm running docker desktop community 2.2.0.0

The opn error could be related to the fact that gulp serve tries to start a browser which it can't do inside the docker image. As such, you should be able to ignore that error. Are you seeing any other errors further down the output?

The problem i'm having is the server doesn't seem to be reachable or not successfully started. When I navigate the address on the browser, I get "This site can't be reached".
For web part I get this when I navigate to the workbench. And for List View, command menus are not loaded and if I navigate to https://localhost:4321/temp/manifests.js, again I get site can't be reached.

In the docker Linux host I have no error after the initial opn error, the output is as shown in the screen above with status of Finished subtask.

Could it be that your firewall or network settings are blocking access to the container?

I'm at a loss now... I'm using a personal machine with no special setup. I turned off my out of the box Windows Firewall and the result was the same. Not using any special network or configuration. Also in Docker can't see anything saying blocked (I know this don't proof anything).

Anyway if there is no wider issue then I will close this and park this. May be I've got some missing setup unique to my environment?

If you wanted to verify your setup, perhaps you could try to run a different container, just to verify that you can communicate with it. You could for example try https://hub.docker.com/r/strm/helloworld-http/ to see if it works on your machine.

Thanks for that @waldekmastykarz. Yes it does work

image

This is my spfx image setup environment, if this looks ok then what else could be the issue?

image

Check, that brings us a step closer. I suspect HTTPS to be the issue here. Which browser are you using?

Using Chrome, Edge and IE. All Can't connect securely to this page. So what's the pointer or where is settings required or need setting?
Thanks

Can you access https://localhost:4321/temp/workbench.html after running gulp serve in the container? By default the SPFx toolchain navigates to https://localhost:5432/workbench which then redirects you to the workbench. In some cases, the redirect doesn't work, while accessing the workbench directly works just fine.

Had a chance to deep dive into this today. One big step forward, I finally was able to communicate when I add "hostname": "0.0.0.0", to serve.json file. Once set, connection came alive.

But my application is not working, the debug is pointing to ?debug=true&noredir=true&debugManifestsFile=https://0.0.0.0:4321/temp/manifests.js which I cannot navigate to. When hostname is not included, then it uses this uri https://localhost:4321/temp/manifests.js which I can only navigate to when hostname is included.

How can I make my app now work when hostname is included in serve.json? Thanks

@waldekmastykarz your fix here solved the issue i was getting after adding hostname in the serve json file.

So does that mean this issue hasn't been fixed because the your post date back to Oct 2018? Anyway this fix certainly got me going.

Phew! Glad I got to the end of this. Many thanks for your help as ever 👍

Great to hear I could help and you got it to work! At this stage, I'm not sure if it's indeed a bug or if it's just how things are. I had conversations with the SPFx team about officially supporting docker but as far as I know they've prioritized different things first. If it's very important you, it would be good to bring it up in the issue list in the sp-dev-docs repo to get their latest stance on it.