Jest not parsing es6: SyntaxError: Unexpected token import

前端 未结 3 721
一个人的身影
一个人的身影 2021-02-19 00:45

I am trying to setup Jest with my webpack project. When I run my tests, Jest complains it cannot read es6 code. Babel seems to not transform my test files.

I have tried

3条回答
  •  孤城傲影
    2021-02-19 00:55

    I have some useful information that can be used as a reference for those who see this problem later.

    By default, transformIgnorePatterns in jest config was ["/node_modules/", "\.pnp\.[^\/]+$"]

    If some guys issue was caused by some code in node_modules and do not overwrite this value, babel-jest still not working.

    Maybe the correct value like this "/node_modules/(?!(your-third-part-es-module-code|others-es-lib))"

提交回复
热议问题