我正在尝试使用 Typescript、Webpack 和 Babel 制作一个 React 库,但是遇到了问题。如果我构建然后将库导入到 React 项目中,那么我的导入是“未定义”(请参阅下面的错误)。我认为这是因为在 中bundle.js没有module.exports代表我的类的变量,只有 a __webpack_exports__["default"] = (ExampleComponent);(但是我不确定这在实践中会做什么,所以我可能是错的。)
我特别收到这个错误:
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.
Run Code Online (Sandbox Code Playgroud)
我尝试过的: