DomParfitt / graphviz-react

React component for displaying Graphviz graphs
MIT License
101 stars 21 forks source link

graphviz-react 1.2.3 not resolved correctly with create-react-app #76

Closed jake-goldsmith closed 1 year ago

jake-goldsmith commented 1 year ago

I am unable to set up a create-react-app project using graphviz-react 1.2.3.

Steps to reproduce:

  1. npx create-react-app graphviz-test --template typescript
  2. cd graphviz-test
  3. npm install graphviz-react
  4. Amend the default App.tsx file as follows
import React from 'react';
import logo from './logo.svg';
import './App.css';
import { Graphviz } from "graphviz-react";

function App() {
    return (
        <div className="App">
            <header className="App-header">
                <img src={logo} className="App-logo" alt="logo"/>
                <p>
                    Edit <code>src/App.tsx</code> and save to reload.
                </p>
                <a
                    className="App-link"
                    href="https://reactjs.org"
                    target="_blank"
                    rel="noopener noreferrer"
                >
                    Learn React
                </a>
                <Graphviz dot={`graph {
                  grandparent -- "parent A";
                  child;
                  "parent B" -- child;
                  grandparent --  "parent B";
                }`}/>
            </header>
        </div>
    );
}

export default App;

Output of npm run build:

npm run build

> graphviz-test@0.1.0 build
> react-scripts build

Creating an optimized production build...
Failed to compile.

Module not found: Error: Can't resolve 'graphviz-react' in 'path-to-project/graphviz-test/src'

This gives a package.json of:

{
  "name": "graphviz-test",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "@types/jest": "^27.5.2",
    "@types/node": "^16.11.64",
    "@types/react": "^18.0.21",
    "@types/react-dom": "^18.0.6",
    "graphviz-react": "^1.2.3",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "typescript": "^4.8.4",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Is the issue caused by using React 18? I wonder if it might work if I was using an older version of create-react-app. I'm currently using create-react-app version 5.0.1.

DomParfitt commented 1 year ago

@jake-goldsmith This should be fixed in 1.2.4.