Skip to content

Can't get the import working in TypeScript #185

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

Open
arpadgabor opened this issue Apr 5, 2021 · 2 comments
Open

Can't get the import working in TypeScript #185

arpadgabor opened this issue Apr 5, 2021 · 2 comments

Comments

@arpadgabor
Copy link
Contributor

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
Copy link

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
Copy link

novelnet commented Aug 13, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants