question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fails to detect components if used with recent react-intl

See original GitHub issue

So when using recent react-intl (^2.0.0-pr-2), you need to change classes in a way that breaks react-docgen:

export default class HomeButton extends React.Component {

becomes:

import {defineMessages, injectIntl, intlShape} from 'react-intl';
class GeocodingResults extends React.Component {
}
export default injectIntl(GeocodingResults);
Error with path "js/components/HomeButton.test.js": Error: No suitable component definition found.
Error: No suitable component definition found.
    at parse (/Users/bartvandeneijnden/opengeo/git/sdk/node_modules/react-docgen/dist/parse.js:73:11)
    at Object.defaultParse [as parse] (/Users/bartvandeneijnden/opengeo/git/sdk/node_modules/react-docgen/dist/main.js:65:33)
    at /Users/bartvandeneijnden/opengeo/git/sdk/node_modules/react-docgen/bin/react-docgen.js:99:35
    at /Users/bartvandeneijnden/opengeo/git/sdk/node_modules/react-docgen/node_modules/node-dir/lib/readfiles.js:110:34
    at fs.js:334:14
    at FSReqWrap.oncomplete (fs.js:95:15)

Is there a way around this? TIA.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
bartvdecommented, Jun 3, 2016

@tizmagik I’m using a small script, here is the code snippet:

var reactDocs = require('react-docgen');
var fs = require('fs');
var path = require('path');
var generateMarkdown = require('./generateMarkdown');

var dir = 'js/components/';
var output = 'docs/api/';

fs.readdir(dir, function(err, files) {
  if (err) {
    throw err;
  }
  files.forEach(function(file) {
    if (path.extname(file) === '.js' || path.extname(file) === '.jsx') {
      fs.readFile(dir + file, 'utf-8', function(err,src) {
        if (err) {
          throw err;
        }
        var componentInfo;
        try {
          componentInfo = reactDocs.parse(src, reactDocs.resolver.findAllComponentDefinitions);
        } catch(e) {
        }
        if (componentInfo  && componentInfo[0].description !== '') {
          var name = file.split('.')[0];
          var markdown = generateMarkdown(name, componentInfo[0]);
          fs.writeFileSync(output + name + '.md', markdown);
        }
      });
    }
  });
});
0reactions
tizmagikcommented, Jun 3, 2016

@bartvde do you mind sharing where you landed with this? I’m having a similar issue and can’t seem to use the component found by findAllComponentDefinitions()

Read more comments on GitHub >

github_iconTop Results From Across the Web

got production error after upgrade React-Intl, Could not find ...
got production error after upgrade React-Intl, Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.
Read more >
React Intl: Internationalize your React apps - LogRocket Blog
In this guide, we'll learn how to use the React Intl library to set up internationalization in a React project. We'll create a...
Read more >
React Intl | Testing Library
If multiple elements have the same string/substring text, find-and-replace may be hard to use reliably. Mock the translation library, If your ...
Read more >
Internationalization in React Apps using react-intl | by Mahesh
We have been using defaultMessage prop in <Formatted*/> components to provide fallback messages in case of failure in locale detection or ...
Read more >
Components | Format.JS
All apps using React Intl must use the <IntlProvider> or <RawIntlProvider> component. This component is used to setup the i18n context for a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found