fetch-mock icon indicating copy to clipboard operation
fetch-mock copied to clipboard

"SyntaxError: Cannot use import statement outside a module" when importing fetchMock from fetch-mock

Open flixman opened this issue 2 years ago • 2 comments

I am a newbee with fetch-mock, using jest for a React code, on typescript (targetting ESNext). I am getting the following error, which I do not understand:

/home/user/Documents/project/node_modules/node-fetch/src/index.js:9
    import http from 'node:http';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

I have followed the advise for jest for typescript, using babel and so... but I cannot get this to work. Any idea on what might be wrong?

flixman avatar Sep 30 '23 14:09 flixman

Seeing this exact same issue (only on JS code). Tried everything I can find online with no luck.

msiden-wl avatar Feb 14 '24 15:02 msiden-wl

Hope this helps:

  • https://github.com/node-fetch/node-fetch/issues/1588
  • https://stackoverflow.com/questions/72706090/error-syntaxerror-cannot-use-import-statement-outside-a-module-when-using-nod?noredirect=1#comment128426614_72706090

dreadwail avatar Apr 29 '24 21:04 dreadwail