如何在 create-react-app 中导入 ES6 模块而不导致测试失败?

How do I import ES6 Module within a create-react-app without causing tests to fail?

当我按照说明发现here

并添加他们指定的导入参考:

import "@ui5/webcomponents/dist/Button";

应用程序运行良好,能够导入按钮。 但是,当我 npm run test 时,出现错误:

SyntaxError: Cannot use import statement outside a module.

知道如何解决这个问题吗?

已提供答案here

{
   "jest": {
      "transformIgnorePatterns": [
         "node_modules/(?!(@ui5|lit-html)).*\.js$"
      ]
   }
}

改为:"test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!@codemirror)/\"",