knee-cola/jest-mock-axios

version 4.6.0 gives SyntaxError: Cannot use import statement outside a module

meltalite opened this issue · 7 comments

Issue:
Our test in the CI suddenly failed today.

 /app/node_modules/jest-mock-axios/dist/index.js:22
    import { jest } from "@jest/globals";
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

    > 1 | import mockAxios from 'jest-mock-axios';
        | ^
      2 | mockAxios.__defineGetter__('CancelToken', function() {
      3 |   return {
      4 |     source: () => {

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1728:14)
      at Object.<anonymous> (src/__mocks__/axios.js:1:1)

Root cause:
in our package.json, we use ^4.5.0, so our CI picked up release 4.6.0 which enables experimental support for native ESM

Hi,

sorry for the inconvenience; I guess the experiment failed here. Is it okay for you to pin to 4.5.0 for the moment?

I'll have to figure out if there is a way to adequately support both ESM and CJS in one release (I thought the current way would do it...). Otherwise I'll probably push 4.6.1, rolling back the ESM changes and pushing 5.0.0 version instead (as initially planned).

I don't mind at all. But I think it's better to push 4.6.1 so no one else will accidentally get into the same trouble again.

We ran into this today as well. We had our dependency defined as ^4.3.0, and once we figured out what was going on, locking it down to ~4.3.0 fixed it for us.

Agreed that this should have been a major version bump to 5.0.0, and in the mean time a release of 4.6.1 that rolls it back sounds like the right thing to do. 👍

Just published 4.6.1. Please check if this works for you

Checked, the issue no longer occurred in 4.6.1. ✅

ps: sorry for the delayed response due to the holiday

Hi, I'm testing with 4.6.1 and the issue is still present for me

Also still seeing this error with 4.6.1, sadly.