sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

Manifest file references hostname value from serve.json in URL for scriptResources

Open dannyjessee opened this issue 5 years ago • 13 comments

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Developer environment

Linux

What browser(s) / client(s) have you tested

  • [ ] 💥 Internet Explorer
  • [ ] 💥 Microsoft Edge
  • [ ] 💥 Google Chrome
  • [ ] 💥 FireFox
  • [ ] 💥 Safari
  • [ ] mobile (iOS/iPadOS)
  • [ ] mobile (Android)
  • [X] not applicable
  • [ ] other (enter in the "Additional environment details" area below)

Additional environment details

Docker Desktop 3.3.3 Linux container image running SharePoint Framework 1.12.1 (Node.js 14.17.0)

Describe the bug / error

In order to support testing and debugging client-side web parts in the workbench when running the SPFx developer toolchain within a container such as Docker, instructions for previous versions of SPFx required three changes:

  1. Adding a hostname value of 0.0.0.0 to config/serve.json.
  2. Adding a debugBasePath value of https://localhost:4321 in config/write-manifests.json.
  3. Adding the statement if (!spBuildCoreTasks.writeManifests.taskConfig.debugBasePath) at line 96 of node_modules/@microsoft/sp-build-web/lib/SPBuildRig.js (the relevant section of this file no longer exists in SPFx 1.12.1).

I believe due to the fact that the relevant section of SPBuildRig.js referenced in step 3 above no longer exists, running gulp bundle after following steps 1-2 above generates a manifest file containing the following (see attached file):

"loaderConfig": { "internalModuleBaseUrls": [ "https://0.0.0.0:4321/dist/" ]

This leads to the following error when attempting to load the web part within either the local or hosted workbench:

[SPLoaderError.loadComponentError]: Failed to load component "b0605d1f-279b-4de4-8f73-66b694df270c" (HelloWorldWebPart). Original error: Failed to load URL 'https://0.0.0.0:4321/dist/HelloWorldWebPartStrings_en-us.js' for resource 'HelloWorldWebPartStrings' in component 'b0605d1f-279b-4de4-8f73-66b694df270c' (HelloWorldWebPart). There was a network problem. This may be a problem with a HTTPS certificate. Make sure you have the right certificate.

INNERERROR: Failed to load URL 'https://0.0.0.0:4321/dist/HelloWorldWebPartStrings_en-us.js' for resource 'HelloWorldWebPartStrings' in component 'b0605d1f-279b-4de4-8f73-66b694df270c' (HelloWorldWebPart). There was a network problem. This may be a problem with a HTTPS certificate. Make sure you have the right certificate. CALLSTACK: Error at SPLoaderError.SPError [as constructor] (https://localhost:4321/temp/workbench-packages/@microsoft_sp-webpart-workbench/local-workbench/sp-webpart-workbench-assembly_en-us.js:38476:23) at new SPLoaderError (https://localhost:4321/temp/workbench-packages/@microsoft_sp-webpart-workbench/local-workbench/sp-webpart-workbench-assembly_en-us.js:52330:28) at Function.ff4n.ErrorBuilder.buildErrorWithVerboseLog (https://localhost:4321/temp/workbench-packages/@microsoft_sp-webpart-workbench/local-workbench/sp-webpart-workbench-assembly_en-us.js:54879:21) at Function.ff4n.ErrorBuilder.buildLoadComponentError (https://localhost:4321/temp/workbench-packages/@microsoft_sp-webpart-workbench/local-workbench/sp-webpart-workbench-assembly_en-us.js:54748:21) at https://localhost:4321/temp/workbench-packages/@microsoft_sp-webpart-workbench/local-workbench/chunk.systemjs-component-loader_en-us.js:1025:75

Steps to reproduce

  1. Install Docker Desktop and launch a container running an image configured with SPFx 1.12.1.
  2. Scaffold a new client-side web part, accepting all defaults from the generator.
  3. Add the appropriate hostname and debugBasePath values outlined in steps 1-2 above.
  4. Note that step 3 above can no longer be followed because the relevant section of SPBuildRig.js no longer exists.
  5. Run gulp bundle and examine the value of loaderConfig : internalModuleBaseUrls in the generated manifest file in the dist folder.

Expected behavior

The generated manifest file should reference the url https://localhost:4321/dist instead of https://0.0.0.0:4321/dist in the loaderConfig : internalModuleBaseUrls.

dannyjessee avatar Jun 07 '21 11:06 dannyjessee

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

ghost avatar Jun 07 '21 11:06 ghost

I'm having the same issue and came to the same conclusion as @dannyjessee. (We have to use Docker for developing/supporting multiple versions of SPFx because we don't have local admin rights on our machines.)

idboyd01 avatar Jun 09 '21 13:06 idboyd01

I also face exactly the same issue, the workaround used to work until @microsoft/[email protected], but now it's no longer possible to run the workbench with Docker on Windows, which is very problematic. It would be nice if the toolchain could be updated to properly support Docker on Windows.

Yvand avatar Jun 10 '21 09:06 Yvand

FYI - Docker isn't an officially supported pattern for SPFx dev from Microsoft.

Ping @waldekmastykarz who's behind the Docker setup...

andrewconnell avatar Jun 15 '21 12:06 andrewconnell

@idboyd01 said:

(We have to use Docker for developing/supporting multiple versions of SPFx because we don't have local admin rights on our machines.)

I've solved this exact thing using NVM which installs Node versions within your profile that you have admin rights to and thus, gets around this

andrewconnell avatar Jun 15 '21 12:06 andrewconnell

FYI - Docker isn't an officially supported pattern for SPFx dev from Microsoft.

Ping @waldekmastykarz who's behind the Docker setup...

For what it's worth, @waldekmastykarz was the one who told me to submit the issue here.

dannyjessee avatar Jun 15 '21 12:06 dannyjessee

@idboyd01 said:

(We have to use Docker for developing/supporting multiple versions of SPFx because we don't have local admin rights on our machines.)

I've solved this exact thing using NVM which installs Node versions within your profile that you have admin rights to and thus, gets around this

Hi @andrewconnell. Do you do this on Windows? I had tried nvm-windows before trying Docker, but at the time (and the docs still suggest) that Windows admin rights are needed for 'nvm install' and 'nvm use', which is why we went with Docker instead. Maybe I'm not up to date, or looking at the wrong NVM?

idboyd01 avatar Jun 15 '21 14:06 idboyd01

FYI - Docker isn't an officially supported pattern for SPFx dev from Microsoft. Ping @waldekmastykarz who's behind the Docker setup...

For what it's worth, @waldekmastykarz was the one who told me to submit the issue here.

The docs suggested Docker as an option, which is why we have been using it.

Does anyone know if there is there an officially supported option for dev that allows developing/supporting multiple SPFx versions without needing admin rights to switch between versions?

idboyd01 avatar Jun 15 '21 14:06 idboyd01

@andrewconnell, the reason I asked @dannyjessee to submit an issue here is because of the change inside SPFx. I understand the patch we've been doing in the past was a no-warranty way of doing it. I thought it would be a good idea to let the PG know of the limitation in SPFx v1.12.1 and see if there is anything that could be done to unblock folks who want to use SPFx in Docker, albeit in a different way than what we used to do in the past.

waldekmastykarz avatar Jun 15 '21 15:06 waldekmastykarz

@idboyd01 said:

Do you do this on Windows?

Lately no... I use macOS. But yes, I have done this on Windows and teach it in my course. Unless something changed with the Windows port, all NVM install does is download the installer and unpack it into a folder within your profile (that you have admin rights to). NVM use just changes your PATH environment variable.

andrewconnell avatar Jun 15 '21 15:06 andrewconnell

I think there is a problem with node_module/@microsoft/spfx-heft-plugins/lib/plugins/webpackConfigurationPlugin/WebpackConfigurationGenerator.js line 376.

This code is not use config/write-manifests.json debugBasePath setting.

HiroakiOikawa avatar Jul 25 '21 03:07 HiroakiOikawa

I think there is a problem with node_module/@microsoft/spfx-heft-plugins/lib/plugins/webpackConfigurationPlugin/WebpackConfigurationGenerator.js line 376.

This code is not use config/write-manifests.json debugBasePath setting.

You are correct. Changing line 376 to the following fixes the issue:

const debugBaseUrl = `${serveConfig.https ? 'https' : 'http'}://localhost:${serveConfig.port || 4321}/dist/`;

dannyjessee avatar Jan 06 '22 14:01 dannyjessee

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

ghost avatar Jan 13 '22 18:01 ghost