Jest gives an error: “SyntaxError: Unexpected token export”

前端 未结 4 1374
不知归路
不知归路 2020-12-17 08:45

I\'m using Jest to test my React app.

Recently, I added DeckGL to my app. My tests fail with this error:

Test suite failed to run

/my_project/node_         


        
4条回答
  •  悲&欢浪女
    2020-12-17 09:10

    This means, that a file is not transformed through TypeScript compiler, e.g. because it is a JS file with TS syntax, or it is published to npm as uncompiled source files. Here's what you can do.

    Adjust your transformIgnorePatterns whitelist:

    {
      "jest": {
        "transformIgnorePatterns": [
          "node_modules/(?!@ngrx|(?!deck.gl)|ng-dynamic)"
        ]
      }
    }

    By default Jest doesn't transform node_modules, because they should be valid JavaScript files. However, it happens that library authors assume that you'll compile their sources. So you have to tell this to Jest explicitly. Above snippet means that @ngrx, deck and ng-dynamic will be transforemed, even though they're node_modules.

提交回复
热议问题