Create-React-App v3没有使用Absolute Imports其他组件运行Jest测试

问题描述 投票:0回答:0

基于( https://facebook.github.io/create-react-app/docs/importing-a-component#absolute-imports )的指导,我试图在我的项目中的两个组件上运行Jest测试( https:/ /github.com/refayathaque/k1y0b1eahsqztk48 )导入其他组件和库。

在本地运行应用程序时,绝对路径导入工作正常,一切都按预期呈现,但在Jest测试期间,绝对路径导入不起作用我相信。

之前我在'.env'文件中使用'NODE_PATH = src /',但CRA3建议我们不要使用'jsconfig.json'文件。 我有'jsconfig.json'文件,但测试仍未运行。 下面的代码是我在'jsconfig.json'文件中的代码:

{
    "compilerOptions": {
      "baseUrl": "src"
    },
    "include": ["src"]
}

来自Jest的错误消息:

Test suite failed to run

    /Users/refayathaque/Documents/k1y0b1eahsqztk48/node_modules/react-s3/lib/ReactS3.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import Signature from "./Signature";
                                                                                                    ^^^^^^^^^

    SyntaxError: Unexpected identifier
reactjs jestjs babeljs
© www.soinside.com 2019 - 2024. All rights reserved.