vis-network
vis-network copied to clipboard
Example code in https://www.npmjs.com/package/vis-network doesn't work
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'
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.
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.