swc-node icon indicating copy to clipboard operation
swc-node copied to clipboard

Cannot use import statement outside a module after upgrading @swc-node/jest

Open meskill opened this issue 2 years ago • 5 comments

After upgrading @swc-node/jest from 1.5.5 to 1.6.2 I get next error while running jest tests.

 /workspaces/app/__integration__/app.test.ts:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs";
                                                                                      ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1678:14)
          at runMicrotasks (<anonymous>)

while having module: "esnext" in the tsconfig

It is probably related to https://github.com/swc-project/swc-node/issues/693

meskill avatar Feb 24 '23 09:02 meskill

Same issue here. I see it's because of this commit: https://github.com/swc-project/swc-node/commit/e353c1a4843671fc7a8f5ccc5727ab260e060565, which overrides the externalHelpers to true for @swc-node/jest. @Brooooooklyn Is it possible to accept option for externalHelpers?

gyz0072004 avatar Feb 28 '23 07:02 gyz0072004

Hello

Did you find a workaround 🙏 ?

thank you!

eltonio450 avatar Apr 05 '23 14:04 eltonio450

Hello

Did you find a workaround 🙏 ?

thank you!

I didn't find a workaround with @swc-node/jest. However, when I turned to @swc/jest our application just worked without problem. You can have a try.

gyz0072004 avatar Apr 10 '23 08:04 gyz0072004

running into similar issues here. Can anyone explain the difference between @swc-node/jest and @swc/jest?

theoephraim avatar May 02 '23 22:05 theoephraim

Also @gyz0072004 - do you have an example of your setup anywhere? Seems to be quite tricky to get everything (including setup / teardown files in TS) to play nicely.

theoephraim avatar May 02 '23 23:05 theoephraim