vendredi 2 octobre 2020

How can I resolve incorrect Svelte CommonJS output?

I'm looking at something which may be a bug in the Svelte compiler. I'm using jest to test svelte components via svelte-jester, which uses the cjs output of the compiler. I have an import of a third party library which is breaking the tests:

// works in dev/build but not test
import naturalCompare from 'natural-compare';
// resulting test cjs line which fails:
const { default: naturalCompare } = require("natural-compare"); // undefined

// works in test but not dev/build
import * as naturalCompare from 'natural-compare';
// resulting test cjs line which works:
const naturalCompare = require("natural-compare"); // function

Here is the export line of the module in question.

This appears to be related to this discussion, but it has been a while and I was wondering if there was a consensus for addressing this, either on my end or in the compiler.

Svelte 3.29.0

Aucun commentaire:

Enregistrer un commentaire