Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[swc-angular-plugin] Issue with Dexie package #325

Closed
kroeder opened this issue Apr 12, 2024 · 2 comments
Closed

[swc-angular-plugin] Issue with Dexie package #325

kroeder opened this issue Apr 12, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@kroeder
Copy link

kroeder commented Apr 12, 2024

Hey,

we currently switch from jest (ts-jest) to swc-angular and encountered a few issues.

One of them being that the "Dexie" package cannot be used anymore

(0 , _dexie.liveQuery) is not a function
TypeError: (0 , _dexie.liveQuery) is not a function

I assumed this is related to cjs vs mjs but whatever I tried with moduleNameMapper, ignoreTransformPattern and everything else I usually do if I enocunter these errors, nothing helped.

So this might either be a bug in swc-angular-plugin or something I'm doing wrong?
It's at least a "regression" since it has worked before and does not now by only following the installation instructions in this package.

Reproduction

https://github.com/kroeder/jest-angular-swc-dexie-reproduction

  1. clone package
  2. npm install
  3. nx test
  4. Test in https://github.com/kroeder/jest-angular-swc-dexie-reproduction/blob/main/src/app/failing-test.spec.ts should fail
@kroeder kroeder changed the title [swc-angular-plugin] Issue with Dexie-package [swc-angular-plugin] Issue with Dexie package Apr 12, 2024
@edbzn edbzn added bug Something isn't working swc-plugin-angular labels Apr 30, 2024
@edbzn
Copy link
Member

edbzn commented Apr 30, 2024

Hi @kroeder, sorry for the late reply, I missed the notification.

It seems to be an issue with SWC handling default imports along with destructured imports because in the failing-test.spec.ts if you replace:

import Dexie, { liveQuery } from 'dexie';

with:

import { Dexie, liveQuery } from 'dexie';

or:

import Dexie from 'dexie';

const { liveQuery } = Dexie;

then it passes:

image

I played a bit with the SWC configuration and it turns out that if you set the noInterop flag:

transform: {
  '^.+\\.(ts|mjs|js)$': ['@swc/jest', {
    module: {
      noInterop: true
    },
    // ...
  }],
}

the failing-test.spec.ts is passing but the rest is failing:

image

@kroeder
Copy link
Author

kroeder commented May 21, 2024

This solved it for us, thanks a lot!

@kroeder kroeder closed this as completed May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants