【问题标题】:Importing default exports are undefined导入默认导出未定义
【发布时间】:2019-11-16 01:28:59
【问题描述】:

我将 TypeScript 与 Babel 7、Webpack 4 和 React 一起使用。

export default () => <span>Test</span>

然后

import Test from './test'

此时测试未定义或plugin-transform-modules-commonjs 为空对象。

.babelrc

  "plugins": [
    "@babel/plugin-syntax-dynamic-import",
    "@babel/plugin-proposal-class-properties",
    "@babel/plugin-proposal-object-rest-spread",
    "@babel/plugin-transform-arrow-functions",
    "@babel/plugin-transform-modules-commonjs",
    "react-hot-loader/babel"
  ],
  "presets": [
    "@babel/preset-react",
    "@babel/preset-typescript",
    ["@babel/preset-env", {
      "targets": {
        "browsers": "> 0.5%, last 2 versions, Firefox ESR, ie 11, not dead"
      }
    }]
  ]
}

tsconfig.json

{
    "compilerOptions": {
    "module": "common",
    "target": "es5",
    "noEmit": true,
    "strict": true,
    "skipLibCheck": true,
    "baseUrl": "./",
    "paths": {
      "*": ["declarations"]
    }
  },
  "include": [
    "src"
  ],
  "exclude": [
    "node_modules"
  ]
}

【问题讨论】:

    标签: reactjs typescript webpack babeljs


    【解决方案1】:

    如果我没记错的话,原来是 react-hot-loader 造成了这个错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-09
      • 2018-04-17
      • 2021-06-17
      • 2022-12-07
      • 1970-01-01
      • 2017-02-06
      • 2018-10-19
      • 2016-07-24
      相关资源
      最近更新 更多