swc-project / swc-node

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

@swc-node/jest needs install @swc/helpers ? #683

Closed sizuhiko closed 1 year ago

sizuhiko commented 1 year ago

Bump @swc-node/jest from 1.5.5 to 1.5.6, has some errors.

 FAIL  test/utils/cookie-utils.test.ts
  ● Test suite failed to run

    Cannot find module '@swc/helpers/lib/_interop_require_wildcard.js' from 'test/utils/cookie-utils.test.ts'

      at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:425:11)
      at Object.<anonymous> (test/utils/cookie-utils.test.ts:14:33)

...

others...

    Cannot find module '@swc/helpers/lib/_interop_require_default.js' from 'src/domain/schema/permission-response-schema.ts'

etc...

I try npm i -D @swc/helpers, then re-run npm t is successfully.

I think better include @swc/helpers to peerDependencies.

stefee commented 1 year ago

I noticed this as well. It would be best to add as a dependency or peer dependency.

gyz0072004 commented 1 year ago

Same issue here.

gyz0072004 commented 1 year ago

Meanwhile, as @swc/helpers is a pure esm module, it requires jest to be configured as esm enabled.

jrolfs commented 1 year ago

I ran into this as well (because of the pure ESM bit). It's technically an @swc/core thing, but @swc-node/jest explicitly enables externalHelpers for some reason:

https://github.com/swc-project/swc-node/blob/83d5f5e771a274f854b3676307954d2d33363027/packages/core/index.ts#L38

To inline the helpers, you can pass the externalHelpers option via the swc configuration section:

module.exports = {
  transform: {
    '^.+\\.(t|j)sx?$': [
      '@swc-node/jest',
      { swc: { jsc: { externalHelpers: false } } }
    ]
  }
}

Unfortunately, passing any of the swc options clobbers everything that @swc-node/jest configures automatically for us (including paths aliases), which kind of defeats the purpose of it altogether. I'm planning on opening a pull request to merge the swc options instead.