netlify-labs / netlify-cms-widget-parent

MIT License
12 stars 9 forks source link

Can't get the import working in TypeScript #185

Open arpadgabor opened 3 years ago

arpadgabor commented 3 years ago

I'm gettin this error when I'm trying to initialize the widget manually in typescript:

Error: Element type is invalid: expected a string (for built-in components)
or a class/function (for composite components) but got: undefined.

You likely forgot to export your component from the file it's defined in,
or you might have mixed up default and named imports. Check the render method of `h`.

This is what I'm trying to do:

import { Control, Preview } from '@netlify/netlify-cms-widget-parent'

CMS.registerWidget('parent', Control, Preview)

// same story with

import * as NetlifyCmsWidgetParent from '@netlify/netlify-cms-widget-parent'

CMS.registerWidget('parent', NetlifyCmsWidgetParent.Control, NetlifyCmsWidgetParent.Preview)

Not sure if I'm doing anything wrong. The plugin works though by initializing using the script.

I'd help with this but I'm not sure where the problem is.

SatoshiGuacamole commented 2 years ago

I'm running into the same issue attempting to register this plugin in Gatsby. It's hard to tell what's exported from the minified distribution. In addition to the notation @arpadgabor posted I also attempted these without success:

import { ParentControl as Control, ParentPreview as Preview } from '@netlify/netlify-cms-widget-parent'
CMS.registerWidget('parent', Control, Preview)
const ParentWidget = require('@netlify/netlify-cms-widget-parent')
CMS.registerWidget('parent', ParentWidget.control, ParentWidget.preview)

Has anyone found a workaround besides resorting to the window?

novelnet commented 1 year ago

any solution?

Got the import working like this, but then crashing when opening the parent dropdown.

import '@netlify/netlify-cms-widget-parent'

const parentWidget = window.NetlifyCmsWidgetParent
CMS.registerWidget('parent', parentWidget.control, parentWidget.preview)