Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to serve react-content-query-webpart with gulp serve --nobrowser #563

Closed
1 of 3 tasks
lworkman opened this issue Jul 11, 2018 · 10 comments
Closed
1 of 3 tasks

Comments

@lworkman
Copy link

lworkman commented Jul 11, 2018

Category

  • Question
  • Bug
  • Enhancement

Authors

@spplante

Expected or Desired Behavior

  1. npm install
  2. gulp serve --nobrowser
  3. Open either a local workbench or workbench on a SharePoint site and interact with the webpart

Observed Behavior

I'm trying to extend the react-content-query-webpart example, but I'm unable to serve it locally for development. When I serve it through gulp serve, I can't access my local workbench to load it. As well, if I try to load it through an SPO workbench, I get an error that the manifests.json file can't be found.

I've even tried setting a GET request with postman against the manifests.json URL, which returns nothing, even though it's worked in the past with other webparts.

If I extract out content-query-webpart-1.4.1.zip and go into that, I have no problem running the webpart locally. However, I would prefer to fork from the main repo so I rebase when necessary.

Steps to Reproduce

  1. Clone the repository
  2. Install dependencies
  3. Run gulp serve --nobrowser
  4. Open any workbench and look in the console to see the manifests.json not found error.
@spplante
Copy link
Contributor

spplante commented Jul 11, 2018

@lworkman You will have to work with the WebPart in a real SharePoint site as I didn't create a mocked version of the service (responsible for all the REST interactions) to be used when running in a workbench context. That basically mean the WebPart will most likely throw errors in the workbench as soon as you'll open the toolpane because it will try to fetch information from SharePoint for getting the available sites, webs, list, fields etc...

Simply follow this article the use the WebPart in "local mode" but deployed in a real SPO site. Basically what you have to do is the following :

  • gulp package-solution (without the --ship flag)
  • gulp serve --nobrowser
  • Add generated .sppkg to catalog of a real SPO site
  • You now have a WebPart running in SPO but using binaries from http://localhost[...]

Using the package-solution command without the --ship flag basically ignores the provided CDN url and makes sure to point to the localhost adress instead, allowing you to update the code locally and see the changes directly in SPO.

On another note, I am not totally sure why it complains about a manifests.json error, did you try to "gulp" the project before trying to serve it? Anyway even if it did not throw this error like I said you would end up with many other errors because the code isn't mocked for a workbench context right now.

It would be a nice contribution if you have time though, adding a small check before initializing the service that would make sure to initialize a mocked version of the service when detecting a workbench context :

 if (Environment.type === EnvironmentType.Local) {
     this.ContentQueryService = new MockedContentQueryService(...);
}
else {
     this.ContentQueryService = new ContentQueryService(...);
}

Let me know if that helps 👍

@spplante
Copy link
Contributor

spplante commented Jul 12, 2018

@lworkman any update in the issue?

I was curious about the manifests.json error so I tried to reproduce it with no success. I downloaded the master repository then I did :

  • npm install
  • gulp serve (without the --nobrowser in order to open the workbench automatically)

And I could add my WebPart to the workbench just fine, like I expected there was some errors once I opened the toolpane because as I explained earlier the REST calls aren't mocked for the workbench context, but otherwise everything works fine for me :

@lworkman
Copy link
Author

Thanks for the response @spplante, I am mainly worried about the manifests.json error right now, as that's what's holding me back. I can deal with the API calls once I get there.

Just from looking at my system, it appears to be an issue with the version of the framework included in the main repository. The package.json is set to use packages in the 1.1.0 range, which is quite old at this point. The project setup with 1.4.1 (which you included as a .zip in the repository for #520) I have no issues with running. I can access the workbench, get the manifest, and work both locally AND through a web hosted workbench. I can do none of those things with the 1.1.0 version.

I don't know if this is because of the node issues older versions of the framework have, or something else entirely.

If you have the time, I suggest updating the main repository to the 1.4.1 version.

@spplante
Copy link
Contributor

spplante commented Jul 12, 2018

@lworkman the zip included at the root of the project is this very same project updated to 1.4.1. The reason why the main project uses 1.1.0 is simple : It is the version supported by SharePoint 2016 onprem. To have a WebPart compatible with SharePoint 2016, I have no choice but to leave it at 1.1.0. Stil today when using the Yeoman generator and selecting the "SP2016 & SPO" compatibility option, it uses 1.1.0.

The downside with 1.1.0 is the fact that you must specify a CDN url where the compiled binaries are stored, something the 1.4.1 version fixed by allowing the sources to be included directly in the .sppkg. So if you are only using the WebPart in SPO, I strongly recommend you to use the 1.4.1 version. I also try to keep both versions in sync so whenever I make a change to the main version I do update the .zip file as well.

That being said, I literally just tried the main package (1.1.0) and I have no manifest error at all, can you confirm that there is no error while the project is gulping? Can you see the generated dist folder? What version of npm are you using?

@lworkman
Copy link
Author

@spplante Ahh, I understand. We might have to leave it at me using the .zip, as I would prefer not to have to deal with the CDNs.

I do know that SPFX versions prior to 1.4.1 had issues with some versions of node and npm, but fixes I've used in the past (like NO_NODE_HTTP2=1) aren't working this time. My npm version is 5.7.1, and I've included my full gulp log below:

Build target: DEBUG
[09:04:44] Using gulpfile ~\Documents\list-sharepoint\sp-dev-fx-webparts\samples\react-content-query-webpart\gulpfile.js
[09:04:44] Starting gulp
[09:04:44] Starting 'serve'...
[09:04:44] Starting subtask 'pre-copy'...
[09:04:44] Finished subtask 'pre-copy' after 21 ms
[09:04:44] Starting subtask 'copy-static-assets'...
[09:04:44] Starting subtask 'sass'...
[09:04:46] Finished subtask 'copy-static-assets' after 1.97 s[09:04:46] Finished subtask 'sass' after 1.99 s
[09:04:46] Starting subtask 'tslint'...
[09:04:46] Starting subtask 'typescript'...
[09:04:46] [typescript] TypeScript version: 2.2.2
[09:04:51] Finished subtask 'typescript' after 5.35 s
[09:04:51] Starting subtask 'ts-npm-lint'...
[09:04:51] Finished subtask 'tslint' after 5.42 s
[09:04:52] Finished subtask 'ts-npm-lint' after 391 ms
[09:04:52] Starting subtask 'api-extractor'...
[09:04:52] Finished subtask 'api-extractor' after 701 μs
[09:04:52] Starting subtask 'post-copy'...
[09:04:52] Finished subtask 'post-copy' after 487 μs
[09:04:52] Starting subtask 'collectLocalizedResources'...
[09:04:52] Finished subtask 'collectLocalizedResources' after 3.84 ms
[09:04:52] Starting subtask 'configure-webpack'...
[09:04:53] Finished subtask 'configure-webpack' after 998 ms
[09:04:53] Starting subtask 'webpack'...
(node:16064) DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/issues/56
parseQuery() will be replaced with getOptions() in the next major version of loader-utils.
[09:05:01] Finished subtask 'webpack' after 8.09 s
[09:05:01] Starting subtask 'configure-webpack-external-bundling'...
[09:05:01] Finished subtask 'configure-webpack-external-bundling' after 2.21 ms
[09:05:01] Starting subtask 'copy-assets'...
[09:05:03] Finished subtask 'copy-assets' after 2.28 s
[09:05:03] Starting subtask 'write-manifests'...
[09:05:04] Finished subtask 'write-manifests' after 630 ms
[09:05:04] Starting subtask 'serve'...
Starting api server on port 5432.
Registring api: /getwebparts
Registring api: /*.*
Registring api: /workbench
[09:05:05] Finished subtask 'serve' after 1.1 s
[09:05:05] Finished 'serve' after 21 s
(node:16064) ExperimentalWarning: The http2 module is an experimental API.
[09:05:05] Server started https://localhost:4321
[09:05:05] LiveReload started on port 35729
[09:05:05] Opening https://localhost:5432/workbench using the default OS app
  Request: [::1] '/workbench'
[09:05:05] ==================[ Finished ]==================
[09:05:06] Project react-content-query-webpart version: 1.0.11
[09:05:06] Build tools version: 2.5.3
[09:05:06] Node version: v8.11.3
[09:05:06] Total duration: 26 s

@spplante
Copy link
Contributor

spplante commented Jul 12, 2018

Hmm yes I remember that NO_NODE_HTTP2 fix I think I had to do this at home because I was working with node v8, I just checked at work right now I am using node v7.4.0, that might be the reason why it works for me.

I will try it out at home tonight to see if it works but I am the one who did the last check-in on the project so I am pretty sure it does work with node v8 but I remember having to follow this resolution in order to make it work :

SharePoint/sp-dev-docs#1002

If you look in the comments it does say "Aaaaaaannnnd this is resolved in the Yeoman Generator v1.4.1. Upgrade to that version for no workaround to use Node.js v8 LTS." which might explain why you don't have the problem with the 1.4.1.

I am pretty sure it doesn't have to do anything with the webpart but most likely running SPFX 1.1.0 with node v8, I will check if I am runing v8 at home tonight and report back.

Edit : Can you post a screenshot of the exact error shown in the UI?

@lworkman
Copy link
Author

This is what I get when I try to open the workbench:
image

This is what I get when I try to open a SPO workbench:
image

And my terminal doesn't report any connection:
image

@spplante
Copy link
Contributor

spplante commented Jul 12, 2018

Hmm it looks like an HTTPS problem, if you look around this problem appears in a lot of different issues, with different fixes depending on the situation.

@lworkman
Copy link
Author

Ahh @spplante, turns out it IS the pre-1.4.1 node issue. I had mistyped the environment variable (NO_NODE_HTTP2=1 vs NODE_NO_HTTP2=1), so the old fix wasn't working. Should have copy/pasted vs. typed it out, I guess.

Not sure if you want to do anything with this information. Locally, I was in the habit of adding a npm "start": "set NODE_NO_HTTP2=1 & gulp serve --nobrowser" command, but I'm not sure what policies you have around that.

Anyways, thanks for your help!

@spplante
Copy link
Contributor

Ah! Good news :)

I am also using node v8 but since it is not totally supported by SPFx I feel like it should stay as-is until it's officially supported, meanwhile people can use the documented fix like you mentionned.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants