打字稿:找不到导出/ JSX元素类型没有任何构造或调用签名

我想将我的Typescript React Component Library用作包。

我的文件如下所示:

MyComponent.tsx:

import React, { FunctionComponent } from 'react';
import styled from 'styled-components';

export interface IProps {
 prop1: boolean;
}

const HeaderWrapper = styled.div`
  width: 100vw;
`;

const MyComponent: FunctionComponent<IProps> = ({prop1}: IProps) => (
  <HeaderWrapper><h1>Test</h1></HeaderWrapper>
);

export default MyComponent;

索引

export * from './components/MyComponent';

I have no errors and can use the component. Then I run tsc with declaration: true. And then I publish my dist folder to npm.

当我在另一个项目中安装软件包时,我会像这样使用它:

import MyComponent from 'my-package';

在构建项目时,出现以下错误:

export 'default' (imported as 'MyComponent') was not found in 'my-package'

TS2604: JSX element type 'MyComponent' does not have any construct or call signatures.

有人可以帮我吗?

非常感谢!