-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to import library in sveltekit #43
Comments
Hey! Thanks for trying out We haven't tried the integration with svelte yet, only React, Angular, and Vue. So we will check this one as well. In the meantime, what could be happening is the following: Web worker files can't be packaged into a single bundle because the browser needs to be able to fetch the script in order to run it as a web worker context. In some frameworks (e.g. Angular) you need to say via configuration where worker files are in order for them to be provided in the frontend context. All in all, it is about packaging and we will get back to you once we figure out how to configure it for svelte! |
Hey! Thanks for your answer. My project is not public but it was just a very basic test using your example on this git repo. I just created a new project with sveltekit (https://kit.svelte.dev/) and dumped the example in there. I will try to have a look later today to see if I can find a way in which I can set the config to properly package the web workers :) |
Here is the answer to the issue: https://kit.svelte.dev/docs/service-workers#during-development
That is the reason why the app can't find
Regardless of that, we still need to see if we can somehow add better fallback checks so Orb moves to the main-thread processing if the web worker fails (to ease out the dev mode in some frameworks). Additionally, I am sure there is a way for this to work in development mode too - there needs to be a way to say to Vite/SvelteKit where to find the web worker file in |
Definitely! Here it is: The project was created as a Typescript project and it works as ES modules (to have
<script lang="ts">
import { onMount } from "svelte";
import { Orb } from "@memgraph/orb";
let container: HTMLElement;
let orb: Orb;
interface MyNode {
id: number;
label: string;
}
interface MyEdge {
id: number;
start: number;
end: number;
label: string;
}
const nodes: MyNode[] = [
{ id: 1, label: 'Orb' },
{ id: 2, label: 'Graph' },
{ id: 3, label: 'Canvas' },
];
const edges: MyEdge[] = [
{ id: 1, start: 1, end: 2, label: 'DRAWS' },
{ id: 2, start: 2, end: 3, label: 'ON' },
];
onMount(() => {
orb = new Orb<MyNode, MyEdge>(container);
orb.data.setup({ nodes, edges });
orb.view.render(() => {
orb.view.recenter();
});
return () => {
orb.view.destroy();
}
});
</script>
<div class="graph" bind:this={container}></div>
<style>
.graph {
width: 400px;
height: 400px;
}
</style> |
Hey! {
"name": "orbtest",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write ."
},
"devDependencies": {
"@sveltejs/adapter-auto": "^1.0.0",
"@sveltejs/adapter-static": "^1.0.6",
"@sveltejs/kit": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte3": "^4.0.0",
"prettier": "^2.8.0",
"prettier-plugin-svelte": "^2.8.1",
"svelte": "^3.54.0",
"svelte-check": "^3.0.1",
"tslib": "^2.4.1",
"typescript": "^4.9.3",
"vite": "^4.0.0"
},
"type": "module",
"dependencies": {
"@memgraph/orb": "^0.1.5"
}
} |
Maybe you were missing the Here are all the steps on how to integrate and run
|
Hey! <script lang="ts">
import { browser } from '$app/environment';
import { onMount } from 'svelte';
var container: any;
var Orb;
interface MyNode {
id: number;
label: string;
}
interface MyEdge {
id: number;
start: number;
end: number;
label: string;
}
const nodes: MyNode[] = [
{ id: 1, label: 'Orb' },
{ id: 2, label: 'Graph' },
{ id: 3, label: 'Canvas' }
];
const edges: MyEdge[] = [
{ id: 1, start: 1, end: 2, label: 'DRAWS' },
{ id: 2, start: 2, end: 3, label: 'ON' }
];
onMount(async () => {
if (browser) {
let mmgraph = await import('@memgraph/orb');
Orb = mmgraph.Orb;
const orb = new Orb<MyNode, MyEdge>(container);
// Initialize nodes and edges
orb.data.setup({ nodes, edges });
// Render and recenter the view
orb.view.render(() => {
orb.view.recenter();
});
}
});
</script>
<div bind:this={container} /> Thanks for your help on this! I believe we can now close this issue :) |
@blazef104 Thanks for sharing another approach, a more dynamic one with fewer restrictions. 👍 |
Hi!
I have been trying to use Orb with sveltekit however I get the following error in the console
As well as some other errors in the browser
I have tried to follow the issue in the browser debugger and it seems to suggest it is due to how Orb imports the default view.
Has anyone ever encountered this before or has an idea of how to solve this?
I am not too much of an expert in javascript so I don't really know where to take it from here. I might try to do some more digging in the following days and see if I can get anywhere.
The text was updated successfully, but these errors were encountered: