swc-project / swc-node

Faster ts-node without typecheck
MIT License
1.72k stars 71 forks source link

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

Open meskill opened 1 year ago

meskill commented 1 year ago

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

gyz0072004 commented 1 year ago

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?

eltonio450 commented 1 year ago

Hello

Did you find a workaround 🙏 ?

thank you!

gyz0072004 commented 1 year ago

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.

theoephraim commented 1 year ago

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

theoephraim commented 1 year ago

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.