hashmd icon indicating copy to clipboard operation
hashmd copied to clipboard

Bytemd 1.12.4 svelte does not seem to work

Open quasarchimaere opened this issue 2 years ago • 8 comments

Somehow adding the Editor (see component code below) does not work, and breaks any page with the editor included:

<script>
  import { Editor } from "bytemd";
  import gfm from "@bytemd/plugin-gfm";
  import bytemdLocaleDe from "bytemd/lib/locales/de.json";
  import bytemdLocaleEn from "bytemd/lib/locales/en.json";
  import { get } from "svelte/store";
  import { stores } from "@sapper/app";
  const { session } = stores();

  const plugins = [gfm()];

  function handleChange(e) {
    content = e.detail.value;
  }

  function changeLocale(locale) {
    if (locale === "de") {
      return bytemdLocaleDe;
    }
    return bytemdLocaleEn;
  }

  $: currentLocale = changeLocale(get(session).locale);

  export let content;

  let tempContent;

  function initContent() {
    if (content && content !== tempContent) {
      tempContent = content;
    }
  }

  $: initContent(content);
</script>

<div class="mb-3">
  <Editor
    value={tempContent}
    plugins={plugins}
    on:change={handleChange}
    locale={currentLocale}
  />
</div>

This error is shown in the console output

TypeError: Cannot read properties of undefined (reading '$$')
    at init$1 (index.esm.js:258:46)
    at new Editor (index.esm.js:35629:5)
    at create_fragment (index.esm.js:4897:1)

we use:

  • svelte 3.46.4
  • sapper 0.29.3
  • rollup 2.70.1

quasarchimaere avatar Mar 29 '22 11:03 quasarchimaere

Thanks for the feedback!

There doesn't seem to be enough information in this error message. Could you please provide a minimal production repo?

And You may want to refer to the Svelte example here

pd4d10 avatar Mar 29 '22 12:03 pd4d10

This issue is stale because it has been open for 60 days with no activity.

github-actions[bot] avatar May 29 '22 02:05 github-actions[bot]

I am having the same issue with the library. When I try to load it into the page it crashes Bildschirmfoto 2022-05-30 um 15 04 29 .

I am not sure if it is caused due to incompatibilty with svelte version or node for example.

"svelte": "^3.47.0",
"webpack": "^5.48.0",

 node 16.11.1

IoannisLafiotis avatar May 30 '22 13:05 IoannisLafiotis

Which version are you using? And it would help to troubleshoot if you can provide a reproduction.

pd4d10 avatar May 30 '22 15:05 pd4d10

this issue still exists until version 1.17.1, seems like the issue is with the precompiled svelte code

eslym avatar Jul 19 '22 03:07 eslym

This issue is stale because it has been open for 60 days with no activity.

github-actions[bot] avatar Sep 18 '22 02:09 github-actions[bot]

i have the same issue with the latest svelte, bytemd 1.17.2 and vite as bundler :(

yonnic avatar Sep 19 '22 18:09 yonnic

script src="https://unpkg.com/bytemd" is not work

GuoJikun avatar Sep 20 '22 03:09 GuoJikun

Solution for me was to import it directly from node_modules:

    //import { Editor } from 'bytemd';
    import Editor from '../node_modules/bytemd/svelte/editor.svelte';

vujovicigor avatar Sep 28 '22 06:09 vujovicigor

Same issue here @vujovicigor `s workaround worked for me

OscarLundberg avatar Oct 11 '22 17:10 OscarLundberg

@vujovicigor thanks for the workaround. Same issue for me.

dbradleyfl avatar Nov 18 '22 19:11 dbradleyfl

@pd4d10 I made a repository with which the problem is reproducible: https://github.com/powellnorma/bytemd-problem It would be great if you could take a look! Thank you.

powellnorma avatar Jan 07 '23 17:01 powellnorma

It seems related to https://github.com/sveltejs/rollup-plugin-svelte/issues/181

pd4d10 avatar Jan 07 '23 17:01 pd4d10

That work around is great @vujovicigor. Thanks

tjands avatar Feb 08 '23 23:02 tjands

This issue is stale because it has been open for 60 days with no activity.

github-actions[bot] avatar Apr 10 '23 01:04 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Apr 17 '23 01:04 github-actions[bot]