react-docgen icon indicating copy to clipboard operation
react-docgen copied to clipboard

No suitable component definition found.

Open BuckyDev opened this issue 5 years ago • 2 comments

Haven't been able to get the JSON output for any component. However, that's working on the Playground app. For instance:

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import './HSource.css';

export default class HSource extends Component {
  static propTypes = {
    url: PropTypes.string.isRequired,
  }

  render() {
    const { url } = this.props;
    return (
      <div
        className='source'
      >
        {url}
      </div>
    )
  }
} 

Ran with:

import HSource from '../../lib/HSource'
const reactDocs = require('react-docgen');
const componentInfo = reactDocs.parse(HSource)

Deps:

"dependencies": {
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-scripts": "3.3.0"
  },
  "devDependencies": {
    "react-docgen": "^5.1.0"
  }

Still can't figure out if that's a bug, if that's my deps or if I'm missing something obvious...

BuckyDev avatar Jan 10 '20 00:01 BuckyDev

I think you can use "raw-loader" with which I can solve this error.

ShouriYang avatar Jan 14 '20 06:01 ShouriYang

Yep it's definitely that the file isn't loaded as a string. I can't find a way to use raw-loader since the syntax has been deprecated. For anyone facing that kind of issue, I solved it by setting up a node server and fetching the endpoint to get the file I needed. Then simply pass it to the parse function and that works

BuckyDev avatar Jan 31 '20 23:01 BuckyDev