运行 在 lerna reactjs 仓库中开玩笑时出现 babel 问题

babel issue when running jest in lerna reactjs repo

我在这个 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.config.json 解决了上述问题,因为 lerna 将尝试执行与每个包相关的代码。