svelte-jester icon indicating copy to clipboard operation
svelte-jester copied to clipboard

Allow to use CJS with Svelte 4 without throwing an error

Open j3rem1e opened this issue 1 year ago • 3 comments

Today, svelte-jester throw an exception if we try to use Svelte 4 with a (classic) cjs setup.

To help with the migration path to esm and jest, it would be great to not throw an exception here but maybe add a warning to the documentation.

It works by chaining babel-jest after svelte-jester if I remove the exception, with the following config:

transform: {
    "\\.svelte$": [
      'jest-chain-transform',
      {
        transformers: [
          'svelte-jester', 'babel-jest'
        ]
      }
    ]
  }

Integrating the transformation esm->csj could be great, but I don't think it's really necessary if it's documented.

j3rem1e avatar Aug 31 '23 09:08 j3rem1e

Interesting. I thought that this would be impossible.

If you start migrating your code, this should an all at once issue. I think it is not possible to mix and match.

sebastianrothe avatar Aug 31 '23 09:08 sebastianrothe

Svelte 4 will only output ESM, but he's setup a transformer to change that output to CJS, so that it will run with Jest. More details here: https://github.com/storybookjs/addon-svelte-csf/issues/132#issuecomment-1699885697

I think it'd be reasonable to try to support it as it'd probably make upgrading to Svelte 4 easier for folks. We can leave ESM as the default

benmccann avatar Sep 01 '23 20:09 benmccann

Svelte 4 will only output ESM, but he's setup a transformer to change that output to CJS, so that it will run with Jest. More details here: storybookjs/addon-svelte-csf#132 (comment)

I think it'd be reasonable to try to support it as it'd probably make upgrading to Svelte 4 easier for folks. We can leave ESM as the default

When will fix?

artemkliaus avatar Oct 06 '23 15:10 artemkliaus