datocms / structured-text

MIT License
22 stars 7 forks source link

Object(...) is not a function error in TypeScript 3.9.7 and Ionic v3(Angular v6) environments #17

Closed nimuseel closed 3 years ago

nimuseel commented 3 years ago

Please consider that it is a translator. πŸ™

Hello, I'm Korean DatoCMS user I'm leaving an issue because I have a question about DataCMS.

Which version of TypeScript is supported by the datocms-structured-text-to-html-string library provided by DatoCMS?

The version of TypeScript I'm using now is version 3.9.7. The framework uses Ionic v3 (Angular v6).

The validate method of datocms-structured-text-utils was used to determine that it was a valid dast grammar. If you use the render method, the error message Object(..) is not a function is output.

Attached is a photo that proves that it is valid when validating with error message below.

image

image

Please contact me if you need more information.

It works in Angular v10 & TypeScript 4.0.3 environments. I look forward to hearing from you. Have a nice day :)

stefanoverna commented 3 years ago

Hi! Can you please paste here the exact structure/data that you're passing to the datocms-structured-text-to-html-string render method please? Angular/TypeScript should not be an issue here, so it must be something else.

nimuseel commented 3 years ago

@stefanoverna Hi, Here's the data.

{
    "schema": "dast",
    "document": {
        "type": "root",
        "children": [
            {
                "type": "paragraph",
                "children": [
                    {
                        "type": "span",
                        "value": "λΉ„μ¦ˆλ„΅ μ„œλΉ„μŠ€ κΈ΄κΈ‰ 점검 쀑!"
                    }
                ]
            },
            {
                "type": "list",
                "style": "bulleted",
                "children": [
                    {
                        "type": "listItem",
                        "children": [
                            {
                                "type": "paragraph",
                                "children": [
                                    {
                                        "type": "span",
                                        "value": "μž‘μ—…μΌμ‹œ: 2021.06.11 μ˜€ν›„ 2μ‹œ ~2021.06.12 μ˜€ν›„ 2μ‹œ"
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "type": "listItem",
                        "children": [
                            {
                                "type": "paragraph",
                                "children": [
                                    {
                                        "type": "span",
                                        "value": "μž‘μ—…μ‚¬ν•­: μ„œλΉ„μŠ€ κ°œμ„ "
                                    }
                                ]
                            }
                        ]
                    }
                ]
            },
            {
                "type": "paragraph",
                "children": [
                    {
                        "url": "https://www.notion.so/bznav/cd055a3c2d8b40579e2867d92b2f3e75",
                        "type": "link",
                        "children": [
                            {
                                "type": "span",
                                "value": "μžμ„Έν•œ 사항 ν™•μΈν•˜κΈ°"
                            }
                        ]
                    }
                ]
            }
        ]
    }
}
stefanoverna commented 3 years ago

Mh, I see no problems here: https://codepen.io/stefanoverna/pen/KKmMxEe

nimuseel commented 3 years ago

Oh... The same error occurs when stored in a separate variable. :(

const data: StructuredTextDocument = {
      schema: 'dast',
      document: {
        type: 'root',
        children: [
          {
            type: 'paragraph',
            children: [
              {
                type: 'span',
                value: 'λΉ„μ¦ˆλ„΅ μ„œλΉ„μŠ€ κΈ΄κΈ‰ 점검 쀑!'
              }
            ]
          },
          {
            type: 'list',
            style: 'bulleted',
            children: [
              {
                type: 'listItem',
                children: [
                  {
                    type: 'paragraph',
                    children: [
                      {
                        type: 'span',
                        value: 'μž‘μ—…μΌμ‹œ: 2021.06.11 μ˜€ν›„ 2μ‹œ ~2021.06.12 μ˜€ν›„ 2μ‹œ'
                      }
                    ]
                  }
                ]
              },
              {
                type: 'listItem',
                children: [
                  {
                    type: 'paragraph',
                    children: [
                      {
                        type: 'span',
                        value: 'μž‘μ—…μ‚¬ν•­: μ„œλΉ„μŠ€ κ°œμ„ '
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            type: 'paragraph',
            children: [
              {
                url: 'https://www.notion.so/bznav/cd055a3c2d8b40579e2867d92b2f3e75',
                type: 'link',
                children: [
                  {
                    type: 'span',
                    value: 'μžμ„Έν•œ 사항 ν™•μΈν•˜κΈ°'
                  }
                ]
              }
            ]
          }
        ]
      }
    };

    const result = render(data);
    console.log(result);
stefanoverna commented 3 years ago

What version of datocms-structured-text-to-html-string are you using?

nimuseel commented 3 years ago

I am using 1.1.4 version. The same error occurs after repeated install and install several times.

nimuseel commented 3 years ago

@stefanoverna Are you following this issue internally? I wish I could get some help...πŸ₯²

stefanoverna commented 3 years ago

Are you able to share a small repository reproducing the issue? I really don't know what could be the cause honestly πŸ™„

nimuseel commented 3 years ago

I think it'll be difficult because it's a company code.. 😒 Could it be related to tsconfig?

stefanoverna commented 3 years ago

it does not need to be the company's code, just a small chunk of code that reproduces the issue (codepen?). my hands are kinda tied otherwise, I'm sorry

nimuseel commented 3 years ago

I tried to set and test the stackblitz according to our project configuration as much as possible, but it works well, and I wonder why it doesn't work well for us. That's why I talked about tsconfig. (or other deep parts)

https://stackblitz.com/edit/ionic-2dwkxk?file=pages/home/home.ts

nimuseel commented 3 years ago

More) I debugged it with Chrome devtool and found that child is undefined in the 42nd row of render.js. However, if you look at the node in the right toolbar 'Scope', you can see that there is a child in the node.

image

stefanoverna commented 3 years ago

It seems to me that children is undefined because you stopped the code execution before the ternary expression was evaluated 100%.

nimuseel commented 3 years ago

Oh, I understand. I'll try to figure it out more internally in this. Please don't close the issue. πŸ™

nimuseel commented 3 years ago

@stefanoverna This issue has been resolved! The array-flatten module was installed in the project and it was solved. Thank you very much for your help. πŸ‘ πŸ™