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

@orbit/record-cache with ESM not working #861

Closed
Thomasan1999 opened this issue Jul 8, 2021 · 8 comments
Closed

@orbit/record-cache with ESM not working #861

Thomasan1999 opened this issue Jul 8, 2021 · 8 comments

Comments

@Thomasan1999
Copy link

When I try to import Orbit packages as ES modules, I get the following error:
record-transform-buffer.ts:33 Uncaught TypeError: Class extends value undefined is not a constructor or null.
It is related to the following line:

import { SyncRecordCache, SyncRecordCacheSettings } from './sync-record-cache';

If I change the import path to '.', it works.

@dgeb
Copy link
Member

dgeb commented Jul 8, 2021

Can you provide a reproduction in a simple public project please?

@Thomasan1999
Copy link
Author

I've found out that the error is triggered only when running Vite dev server, it might be caused by the order of imported files. It works in Vite build though.

I don't know if it's relevant for you anymore, if it is, here is the test project: https://github.com/Thomasan1999/orbit-record-cache-import-test.

@samwightt
Copy link

I'm getting this error on Vite too. I'm using Yarn 2 though, so I'm not sure if that's related to the error or not.

@dgeb
Copy link
Member

dgeb commented Jul 16, 2021

@Thomasan1999 thanks for the test repo, I will investigate soon. I'm glad it seems to be working in Vite build.

@tchak as a Vite user, do you have any ideas here?

@Thomasan1999
Copy link
Author

@dgeb Meanwhile, I've opened another issue in the Vite repo. According to sodatea, it might be related to circular dependencies. A similar issue here.

@samwightt Apparently, if any package provides ESM build, you can exclude them from dependency pre-bundling. @orbit packages provide ESM, so you can use this as a workaround.

import { defineConfig } from "vite";

export default defineConfig({
  optimizeDeps: {
    exclude: [
      '@orbit/indexeddb',
      '@orbit/memory',
      '@orbit/records'
    ]
  }
})

@dgeb
Copy link
Member

dgeb commented Jul 17, 2021

@Thomasan1999 thanks for tracking this down. I can confirm that there is a circular dependency between sync-record-cache.ts and record-transform-buffer.ts in @orbit/record-cache. This cycle would not be trivial to remove, but it is plausible, and I'll consider it. I'm glad that there is an alternate workaround for now.

@dgeb
Copy link
Member

dgeb commented Jul 18, 2021

I decided to remove the cycle in #868 because it cleaned up several aspects of the implementation (see the PR for details). This has been resolved in:

  • @orbit/indexeddb@0.17.0-beta.23
  • @orbit/local-storage@0.17.0-beta.23
  • @orbit/memory@0.17.0-beta.23
  • @orbit/record-cache@0.17.0-beta.23

You can confirm that this fixes the vite/esbuild issue by changing the deps in your test repo to:

-        "@orbit/indexeddb": "0.17.0-beta.21",
-        "@orbit/memory": "0.17.0-beta.21",
-        "@orbit/records": "0.17.0-beta.21"
+        "@orbit/indexeddb": "0.17.0-beta.23",
+        "@orbit/memory": "0.17.0-beta.23",
+        "@orbit/records": "0.17.0-beta.22"

Thanks again for your help tracking this down!

@dgeb dgeb closed this as completed Jul 18, 2021
@Thomasan1999
Copy link
Author

I updated the deps in the test repo and in the project where I actually use them. It works in both now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants