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

Verbose flag not working in Node API #637

Closed
EdwardSalter opened this issue Oct 13, 2017 · 4 comments
Closed

Verbose flag not working in Node API #637

EdwardSalter opened this issue Oct 13, 2017 · 4 comments
Labels

Comments

@EdwardSalter
Copy link

When running the styleguidist server via the node API, no output is displayed at all regardless of the value of the verbose flag in the configuration file.

An example repo of this in action is available here: https://github.com/EdwardSalter/example

Run running the server via the node API, I would expect the output to still be displayed. This is a bit of a problem since any output from webpack is swallowed so a broken build is impossible to fix.

I unfortunately cannot run the styleguidist server via the CLI since I need to set various variables and mocks in my code before starting the server.

@EdwardSalter EdwardSalter changed the title Verbose flag not working from Node-API Verbose flag not working in Node API Oct 13, 2017
@sapegin
Copy link
Member

sapegin commented Oct 16, 2017

That’s because any output is disabled by default in the API, I’ve updated the API docs to clarify that.

@EdwardSalter
Copy link
Author

Ah, thank you for clarifying that. I have just updated my config to add in the logger configuration which has enabled some output but webpack output is still not coming through.
I have updated my example repo to force a webpack error and this is the output I get from running via the CLI:

...
You can now view style guide in the browser.
  Local:            http://localhost:6060/
  On your network:  http://10.0.75.1:6060/
Loading components:
C:\Development\Other\react-styleguidist-example\lib\components\BabelIgnored\BabelIgnored.js
C:\Development\Other\react-styleguidist-example\lib\components\Button\Button.js
C:\Development\Other\react-styleguidist-example\lib\components\Modal\Modal.js
C:\Development\Other\react-styleguidist-example\lib\components\Placeholder\Placeholder.js
C:\Development\Other\react-styleguidist-example\lib\components\PushButton\PushButton.js
C:\Development\Other\react-styleguidist-example\lib\components\RandomButton\RandomButton.js
./lib/components/BabelIgnored/BabelIgnored.js
Module parse failed: C:\Development\Other\react-styleguidist-example\lib\components\BabelIgnored\BabelIgnored.js Unexpected token (5:4)
You may need an appropriate loader to handle this file type.
| const BabelIgnored = () => {
|   return (
|     <div>
|       Ignored by babel
|     </div>

Learn how to add webpack loaders to your style guide:
https://react-styleguidist.js.org/docs/webpack.html
...

and the output I get from the node api:

Listening at http://0.0.0.0:6060
Loading components:
C:\Development\Other\react-styleguidist-example\lib\components\BabelIgnored\BabelIgnored.js
C:\Development\Other\react-styleguidist-example\lib\components\Button\Button.js
C:\Development\Other\react-styleguidist-example\lib\components\Modal\Modal.js
C:\Development\Other\react-styleguidist-example\lib\components\Placeholder\Placeholder.js
C:\Development\Other\react-styleguidist-example\lib\components\PushButton\PushButton.js
C:\Development\Other\react-styleguidist-example\lib\components\RandomButton\RandomButton.js

I now get the Loading components text and I can see the components that have been found but I cannot tell why the webpage gives me just a white screen because the webpack error has been swallowed somewhere.

@sapegin
Copy link
Member

sapegin commented Oct 17, 2017

Looks like the CLI does more error handling:

// Custom error reporting
compiler.plugin('done', function(stats) {
const messages = formatWebpackMessages(stats.toJson({}, true));
if (!messages.errors.length && !messages.warnings.length) {
logger.info(chalk.green('Compiled successfully!'));
}
printAllErrorsAndWarnings(messages, stats.compilation);
});

styleguide.server returns a webpack compiler instance so you can try to attach an event handler to it and see if it works.

@EdwardSalter
Copy link
Author

Yep, I have updated my example repo with code duplicated from the bin/styleguidist.js and it is now working as expected displaying the output in the console.
I would have thought that this behaviour would be a layer deeper in the server function so that it was the same for both the node API and the CLI.
This at least gives me a way of figuring out why my code doesn't compile so I will close the comment.

Thanks for your help @sapegin.

tizmagik added a commit that referenced this issue Oct 24, 2017
* master:
  Refactor: Replace Markdown links with the Link component instead of the styles (#650)
  Docs: Clarify logging in Node API (#637)
  Docs: Correct the `static` modifier note (#643)
  Docs: Explain behavior for code blocks w/o language tag (#642)
  Docs: Fix invalid prop type warning (#639)
  Fix: Clear console on example reload (#638)
  Docs: Add credits for logo designers (#636)
  Fix: Update react-docgen (#635)
  Fix: Correctly print non-Styleguidist exception messages
  Fix: Fix validation error for uglifyjs-webpack-plugin
  Docs: Remove react-modal dependency, tweak examples
  Docs: Update react-styleguidist in CRA example (#632)

# Conflicts:
#	examples/basic/package-lock.json
#	examples/basic/package.json
#	examples/cra/package-lock.json
#	examples/customised/package-lock.json
#	examples/customised/package.json
#	examples/express/package-lock.json
#	examples/express/package.json
#	examples/sections/package-lock.json
#	examples/sections/package.json
#	examples/webpack/package-lock.json
#	examples/webpack/package.json
#	package-lock.json
#	package.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants