Closed
Description
I'm trying to add graphiql to my sapper (svelte + ssr) application by dynamically importing preact and graphiql but i can't get preact/compat working so i can use react components in a preact project.
I use the rollup config provided by sapper and added alias to it:
// ...
alias({
entries: [
{ find: "react", replacement: path.resolve(__dirname, "node_modules/preact/compat/dist/compat.js") },
{ find: "react-dom", replacement: path.resolve(__dirname, "node_modules/preact/compat/dist/compat.js") },
]
}),
resolve({
browser: true,
dedupe,
}),
commonjs(),
// ...
After adding that sapper starts without any errors, but when opening the web server i get a wired error:
preact.js:formatted:1 Uncaught (in promise) TypeError: Cannot convert object to primitive value
at j (preact.module.js:formatted:1)
at T (preact.module.js:formatted:1)
at preact.module.js:formatted:1
at b (preact.module.js:formatted:1)
at b (preact.module.js:formatted:1)
at _ (preact.module.js:formatted:1)
at T (preact.module.js:formatted:1)
at E (preact.module.js:formatted:1)
at show (graphiql.js:7)
My svelte code (to test the react to preact/compat alias i'm using react-greeting):
<script>
import { onMount } from 'svelte';
let rootEl;
onMount(async() => {
const { h, Component, render, createElement } = await import('preact');
const Greeting = await import('react-greeting');
render(createElement(Greeting, {}, null), rootEl);
});
</script>
<div bind:this={rootEl} />
Also placing this code in a js file and dynamically importing that or directly importing and dynamically calling the code in there gives the same result.