Why can't I import Dagre into my Vite app?
Our team is migrating a Vue CLI app to Vite. We had some Dagre code that worked with no problems in the Vue CLI app, but is throwing this error with Vite, stopping the entire app from loading:
Uncaught Error: Dynamic require of "@dagrejs/graphlib" is not supported
Any help is much appreciated!
Code:
// Adapted from https://vueflow.dev/examples/layout/simple.html
import dagre from '@dagrejs/dagre';
import { Position, useVueFlow } from '@vue-flow/core';
import { ref } from 'vue';
export function useLayout() {
const graph = ref(new dagre.graphlib.Graph());
function layout(nodes, edges, direction) {
const dagreGraph = new dagre.graphlib.Graph();
// ...
dagre.layout(dagreGraph);
// ...
return nodes;
}
return { graph, layout };
}