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

[Bug]: babel-jest can not transform antd/es #14656

Closed
1 task done
singsad opened this issue Jun 10, 2022 · 2 comments
Closed
1 task done

[Bug]: babel-jest can not transform antd/es #14656

singsad opened this issue Jun 10, 2022 · 2 comments
Labels
i: third party The report is a problem of third party outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@singsad
Copy link

singsad commented Jun 10, 2022

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

my jest config

  transformIgnorePatterns: ['!/node_modules/','/dist/'],
  transform: { 
    '\\.[jt]sx?$': 'babel-jest',
  },

my package.json

    "jest": "^24.1.0",
    "@babel/preset-env": "^7.0.0",
    "@babel/preset-react": "^7.0.0",
    "@babel/preset-typescript": "^7.8.3",
    "babel-jest": "28.1.1",

When i test antd components, The test suite was failed

/Users/xxx/Desktop/gitlab/fbs-frontend/node_modules/antd/es/select/style/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import '../../style/default.less';
    SyntaxError: Cannot use import statement outside a module

Configuration file name

babel.config.js

Configuration

'plugins': [
      [
      'import',
      {
        'libraryName': 'antd',
        'libraryDirectory': 'es',
        'style': true,
      },
    ],
  ],
  'presets': [
    '@babel/preset-env',
    '@babel/preset-react',
    [
      '@babel/preset-typescript',
      {
        'isTSX': true,
        'allExtensions': true,
      },
    ],
  ],

Current and expected behavior

When i use antd by config 'libraryDirectory': 'es'. My jest reported an error.
But when i use this config 'libraryDirectory': 'lib'. My jest will work.
I don't think babel-jest treats the esmodule of antd as commonjs.

Environment

System:
OS: macOS 11.6.4
Binaries:
Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
npmPackages:
@babel/cli: ^7.2.3 => 7.14.8
@babel/core: ^7.3.4 => 7.15.0
@babel/plugin-proposal-class-properties: ^7.0.0 => 7.14.5
@babel/plugin-proposal-decorators: ^7.0.0 => 7.14.5
@babel/plugin-proposal-object-rest-spread: ^7.0.0 => 7.14.7
@babel/plugin-proposal-optional-chaining: ^7.9.0 => 7.14.5
@babel/plugin-proposal-private-methods: ^7.16.0 => 7.16.0
@babel/plugin-proposal-private-property-in-object: ^7.16.0 => 7.16.0
@babel/plugin-transform-runtime: ^7.0.0 => 7.15.0
@babel/polyfill: ^7.2.5 => 7.12.1
@babel/preset-env: ^7.0.0 => 7.15.0
@babel/preset-react: ^7.0.0 => 7.14.5
@babel/preset-typescript: ^7.8.3 => 7.15.0
@babel/runtime: ^7.0.0 => 7.15.3
babel-jest: 28.1.1 => 28.1.1
babel-loader: ^8.2.3 => 8.2.3
babel-plugin-import: ^1.11.0 => 1.13.3
babel-plugin-lodash: ^3.3.4 => 3.3.4
babel-plugin-react-require: ^3.0.0 => 3.1.3
babel-plugin-react-transform: ^3.0.0 => 3.0.0
eslint: ^7.11.0 => 7.32.0
jest: ^24.1.0 => 24.9.0
webpack: ^5.65.0 => 5.65.0

Possible solution

No response

Additional context

No response

@babel-bot
Copy link
Collaborator

Hey @singsad! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@liuxingbaoyu
Copy link
Member

babel-jest belongs to jest, looks like you should open an issue at https://github.com/facebook/jest.

@liuxingbaoyu liuxingbaoyu added i: third party The report is a problem of third party and removed i: needs triage labels Jun 10, 2022
@liuxingbaoyu liuxingbaoyu closed this as not planned Won't fix, can't repro, duplicate, stale Sep 23, 2022
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Dec 24, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: third party The report is a problem of third party outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants