jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.2k stars 505 forks source link

导出组件报错 #1086

Open XinYueXiao opened 2 years ago

XinYueXiao commented 2 years ago

安装后,测试报错 react.development.js:220 Warning: React.createElement: 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. image

测试组件

const TestCom = () => {
  return (
    <div>
      测试组件导出
    </div>
  )
}

export default TestCom

在index.tsx导出

import TestCom from './lib/TestCom'
export {
  TestCom
}

在example/index.tsx引用

import 'react-app-polyfill/ie11';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { TestCom } from '../.';

const App = () => {
  return (
    <div>
      <TestCom />
    </div>
  );
};

ReactDOM.render(<App />, document.getElementById('root'));