'Using Got, JEST and Typescript, getting nexpected token error

Here is the code, let's call it mycode.ts:

import { Tracer } from 'dd-trace';
import got from 'got';
....
export class MyClass {...}

And then in test, let call it mycode.test.ts, I just load the file

import { MyClass } from './mycode';

I get the following error:

({"Object.":function(module,exports,require,__dirname,__filename,jest){import create from './create.js'; ^^^^^^ Test suite failed to run

Jest encountered an unexpected token
...
SyntaxError: Cannot use import statement outside a module

  1 | import { Tracer } from 'dd-trace';
> 2 | import got from 'got';
    | ^

Any idea what is wrong?



Solution 1:[1]

use this instead

const got = require('got');

and then

got.yourfunctionhere

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ashiq Ali