sindresorhus / ky

🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API
MIT License
11.83k stars 341 forks source link

Cannot use import statement outside a module, Jest #553

Closed net-illia-stetsenko closed 6 months ago

net-illia-stetsenko commented 6 months ago

Hello there Faced with a problem when tried to test my ky client. I use Jest for testing. After running the tests I have received the following error:

node_modules/ky/distribution/index.js:2
    import { Ky } from './core/Ky.js';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

    > 1 | import ky, { KyInstance } from 'ky';
        | ^
      2 |
      3 | import logger from '../logger';
      4 |

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
      at Object.<anonymous> (src/client/api.ts:1:1)
      at Object.<anonymous> (tests/api-tests/v1/get.test.ts:3:1)

Thought, vite is succesfully builds the app Any thoughts?

sindresorhus commented 6 months ago

This is a problem with your Jest config, not this package.