Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用babel7后,按需加载执行报错 #424

Open
ForeverPx opened this issue Mar 13, 2020 · 2 comments
Open

使用babel7后,按需加载执行报错 #424

ForeverPx opened this issue Mar 13, 2020 · 2 comments

Comments

@ForeverPx
Copy link

错误信息

image

对应代码

import { DatePicker } from 'antd';
const { RangePicker } = DatePicker;

.babelrc

{
    "presets": [
        "@babel/preset-react",
        [
            "@babel/preset-env"
        ],
        "@babel/preset-typescript"
    ],
    "ignore": [
        "./src/common/UEditor/ueditor.all.js"
    ],
    "plugins": [
        "react-hot-loader/babel",
        [
            "react-css-modules",
            {
                "filetypes": {
                    ".less": {
                        "syntax": "postcss-less"
                    }
                },
                "webpackHotModuleReloading": true,
                "generateScopedName": "[name]__[local]__[hash:base64:5]"
            }
        ],
        ["@babel/plugin-transform-runtime", {
            "corejs": false, // 下面详解
            "helpers": false, // 助手函数是否提取,同babel-plugin-transform
            "regenerator": true, // 同babel-plugin-transform
            "useESModules": false
        }],
        [
            "import",
            {
                "libraryName": "antd",
                "libraryDirectory": "es",
                "style": "css"
            }
        ],
        [
            "module-resolver",
            {
                "root": [
                    "./src"
                ],
                "alias": {
                    "@common": "./src/common",
                    "@main": "./src/app/main"
                }
            }
        ],
        "@babel/plugin-syntax-dynamic-import",
        "@babel/plugin-syntax-import-meta",
        "@babel/plugin-proposal-class-properties",
        "@babel/plugin-proposal-json-strings",
        [
            "@babel/plugin-proposal-decorators",
            {
                "legacy": true
            }
        ],
        "@babel/plugin-proposal-function-sent",
        "@babel/plugin-proposal-export-namespace-from",
        "@babel/plugin-proposal-numeric-separator",
        "@babel/plugin-proposal-throw-expressions",
        "@babel/plugin-proposal-export-default-from",
        "@babel/plugin-proposal-logical-assignment-operators",
        "@babel/plugin-proposal-optional-chaining",
        [
            "@babel/plugin-proposal-pipeline-operator",
            {
                "proposal": "minimal"
            }
        ],
        "@babel/plugin-proposal-nullish-coalescing-operator",
        "@babel/plugin-proposal-do-expressions",
        "@babel/plugin-proposal-function-bind",
        "@babel/plugin-transform-destructuring",
        "@babel/plugin-transform-modules-commonjs"
    ],
    "env": {
        "dev": {
            "plugins": [
                "istanbul"
            ]
        }
    }
}
@youngBrain1893
Copy link

youngBrain1893 commented Apr 10, 2020

istanbuljs/babel-plugin-istanbul#161

同样的问题 +1

当使用 babel-plugin-istanbul + 导出内容解构 的时候 import of DatePicker 被丢掉了

本应该得到

// 不开启 istanbul 插件
import "antd/es/date-picker/style/css";
import _DatePicker from "antd/es/date-picker";
const {
  RangePicker
} = _DatePicker;

实际实际编译后只剩下了,由于没有 DatePicker 引入 RangePicker 结构失败

const {
  RangePicker
} = (cov_1rg8pvnktm().s[0]++, DatePicker);

最小可复现内容
.babelrc

{
  "presets": [],
  "plugins": [
    [
      "import",
      {
          "libraryName": "antd",
          "libraryDirectory": "es",
          "style": "css"
      }
    ],
    "babel-plugin-istanbul"
  ]
}

index.js

import { DatePicker } from 'antd';
const { RangePicker } = DatePicker;
// const RangePicker = DatePicker.RangePicker // 不使用解构语法的时候也没问题

console.log(RangePicker);

@chenabc1
Copy link

请问这问题解决了吗现在?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants