Search code examples
javascriptvis.js

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?


Solution

  • 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);
    }