小编Rob*_*son的帖子

React 项目中未定义 Webpack + Typscript 库导入

我正在尝试使用 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)

我尝试过的:

  • 将 tsconfig 目标更改为 es6,将模块更改为 commonjs
  • 将 tsconfig 目标更改为 es6,将模块更改为 esnext
  • 将 tsconfig 目标更改为 es5,将模块更改为 esnext
  • 将 …

javascript typescript webpack babeljs

0
推荐指数
1
解决办法
3373
查看次数

标签 统计

babeljs ×1

javascript ×1

typescript ×1

webpack ×1