reactjsjestjsvitequery-stringbabel-jest

Jest error: Jest encountered an unexpected token - query-string import


I'm getting the following:

jest fail error image

babel.config.json:

{
  "presets": [
    ["@babel/preset-env", { "targets": { "esmodules": true } }],
    ["@babel/preset-react", { "runtime": "automatic" }]
  ]
}

jest.config.js:

export default {
  testEnvironment: 'jest-environment-jsdom',
};

I have "type": "module" set in the package.json

query-string version is 9.0.0 & using Vite

What triggers the error is the rendering of the <PublicRoute /> component:

render(
      <AuthContext.Provider value={contextValue}>
        <PublicRoute>
          <h1>Test</h1>
        </PublicRoute>
      </AuthContext.Provider>
    );

Checked the following query-string Github thread but no luck.


Solution

  • Ideally, I'd prefer a solution for query-string v9 or latest, if anyone has it.

    Having said that, downgrading to v7 solved it.