score:0

jest currently doesn't understand either import or export. it looks like you followed common setup docs for your jest config so you're probably using babel and transpiling your code from using modules to using commonjs, but you're not transpiling your dependencies:

transformignorepatterns: [
  "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$", // <-- do not transform node_modules
  "^.+\\.module\\.(css|sass|scss)$",
],

but, what's causing your problem is that one of your exports (amcharts) needs to be transformed in order to make those import/export statements compliant with the commonjs format that jest is expecting.

your easiest fix is probably to edit the transformignorepatterns:

transformignorepatterns: [
    //add other modules here that ship esm that jest doesn't like
    'node_modules/(?!@amcharts)',
    "^.+\\.module\\.(css|sass|scss)$",
  ],

so we're saying "go ahead and don't transform anything in node modules unless it matches @amcharts. if you get more dependencies that need to be transformed, then you can add it to that regex.

for a different solution, if you like experimental features, then you can try turning on jest's experimental support for esm: https://jestjs.io/docs/ecmascript-modules.


Related Query

More Query from same tag