Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReferenceError: vis is not defined

I installed vis.js through npm npm install vis-network

and already require it in my app.js

try {
    require('vis-network');
} catch (e) { }

and recompiled it in laravel mix

npm run dev

but whenever I instantiate a vis instance I always get vis is not define error on console..

<script>
let nodes = new vis.DataSet(_nodes),
    edges = new vis.DataSet(_connections);

...
let network = new vis.Network(container, { nodes: nodes, edges: edges }, _options);
</script>

What am I missing?

like image 651
saionachi Avatar asked Feb 23 '26 22:02

saionachi


1 Answers

Try adding it to the window object, to escape the node encapsulating context.

try {
    window.vis = require('vis-network/standalone');
} catch (e) {
    console.error(e);
}
like image 188
Tschallacka Avatar answered Feb 25 '26 11:02

Tschallacka