visjs / vis-network

:dizzy: Display dynamic, automatically organised, customizable network views.
https://visjs.github.io/vis-network/
Apache License 2.0
2.98k stars 364 forks source link

Example code in https://www.npmjs.com/package/vis-network doesn't work #1608

Open jerryajay opened 2 years ago

jerryajay commented 2 years ago

I tried using the example code on npm website as such:


import { DataSet } from "vis-network";
import { Network } from "vis-network";

function GraphExp() {

    var nodes = new DataSet([
        {id: 1, label: 'Node 1'},
        {id: 2, label: 'Node 2'},
        {id: 3, label: 'Node 3'},
        {id: 4, label: 'Node 4'},
        {id: 5, label: 'Node 5'}
    ]);

    var edges = new DataSet([
        {from: 1, to: 3},
        {from: 1, to: 2},
        {from: 2, to: 4},
        {from: 2, to: 5}
    ]);

    var data = {
        nodes: nodes,
        edges: edges
    };

    var options = {};

    var network = new Network(document.getElementById('mynetwork'), data, options);

    return(
        <div id="mynetwork">

        </div>
    );

}

export default GraphExp;

I get the error:

Failed to compile.

./node_modules/vis-network/peer/umd/vis-network.min.js Module not found: Can't resolve 'vis-data/peer/umd/vis-data.js' in 'C:\Users\jerry\OneDrive\Desktop\CSC499\React- Experiments\node_modules\vis-network\peer\umd'

fayeah commented 2 years ago

yeah, I got the same problem, can anyone help to explain? But I guess maybe it's becos the vis-data.js module is revoked by vis-network, but not been installed when we only add vis-network library.

fayeah commented 2 years ago

got it. we need to install vis-data as well. Run npm i vis-data and then the error is cleared. But I think the author should include it in dependencies rather than in peerdependencies.