【问题标题】:babel issue when running jest in lerna reactjs repo在 lerna reactjs repo 中运行 jest 时出现 babel 问题
【发布时间】:2020-11-25 17:05:45
【问题描述】:

我在这个 repo 中重新创建了问题:

https://github.com/umarmw/lopital-sdk

在执行lerna run test时,会抛出这个错误:

FAIL __tests__/doctor.test.js
  ● Test suite failed to run

    SyntaxError: /codebox/lopital-sdk/packages/doctor/__tests__/doctor.test.js: Support for the experimental syntax 'jsx' isn't currently enabled (9:24):

       7 | describe('doctor', () => {
       8 |     it('should be selectable by class "foo"', function() {
    >  9 |         expect(shallow(<Doctor title="MO" />).is('.btn-doctor')).toBe(true);
         |                        ^
      10 |       });
      11 | 
      12 |       it('should mount in a full DOM', function() {

    Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation.
    If you want to leave it as-is, add @babel/plugin-syntax-jsx (https://git.io/vb4yA) to the 'plugins' section to enable parsing.

我已经在 babel 预设中添加了这个@babel/preset-react,但这并没有解决问题。

有什么想法吗?

【问题讨论】:

  • 你也安装了@babel/preset-react吗?
  • 您是否尝试将格式更改为jsx
  • @yaya,我试过了……但还是不行。
  • @Rashomon,它是一个打字稿项目。扩展名应该是 ts 或 tsx。

标签: reactjs jestjs babeljs lerna


【解决方案1】:

我已通过在每个包文件夹中添加babel.config.json 来解决上述问题,因为lerna 将尝试执行与每个包相关的代码。

【讨论】:

    猜你喜欢
    • 2019-04-04
    • 2016-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    • 2012-07-14
    • 2022-09-16
    相关资源
    最近更新 更多