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

Can not create MemorySource #933

Closed
towerhe opened this issue Mar 1, 2022 · 5 comments · Fixed by #937
Closed

Can not create MemorySource #933

towerhe opened this issue Mar 1, 2022 · 5 comments · Fixed by #937

Comments

@towerhe
Copy link

towerhe commented Mar 1, 2022

I try to run a test with vitest. It throws an error when creating an instance of MemorySource:

FAIL  test/unit/menu.spec.ts [ test/unit/menu.spec.ts ]
TypeError: Cannot read properties of null (reading 'nextTick')
 ❯ Object.<anonymous> node_modules/@orbit/record-cache/dist/commonjs/live-query/live-query.js:86:41
 ❯ Object.<anonymous> node_modules/@orbit/record-cache/dist/commonjs/live-query/sync-live-query.js:4:22

My test codes:

const schema = new RecordSchema({
  models: {
    menuItem: {
      attributes: {
        path: { type: "string" },
        title: { type: "string" },
        icon: { type: "string" },
        disabled: { type: "boolean" },
        hidden: { type: "boolean" },
      },
      relationships: {
        parent: { kind: "hasOne", type: "menuItem", inverse: "children" },
        children: { kind: "hasMany", type: "menuItem", inverse: "parent" },
      },
    },
  },
});

const memory = new MemorySource({ schema });

test("create an memory source", () => {
  // nothing here
});
@dgeb
Copy link
Member

dgeb commented Mar 1, 2022

I'm not seeing any code that would instantiate a liveQuery, which makes the error message and trace confusing. Any chance you could reproduce your problem in a fork of this codesandbox or in a public repo?

@towerhe
Copy link
Author

towerhe commented Mar 2, 2022

@dgeb I pushed a test project to https://github.com/towerhe/orbit-vitest.

It can reproduce my problem.

Thanks !

dgeb added a commit that referenced this issue Mar 6, 2022
Use optional chaining to handle cases in which the global `process` is `null` (because `typeof null === 'object'`).

Fixes #933
@dgeb dgeb closed this as completed in #937 Mar 6, 2022
@dgeb
Copy link
Member

dgeb commented Mar 6, 2022

@towerhe thanks for the reproduction! That helped me narrow the issue down to an edge case in the environment check (in which the process global could be null instead of undefined). I've patched this in #937 and will get a patch release out soon.

Incidentally, I was surprised to see the commonjs dist being used instead of modules (ESM). I'm new to vite and vitest - is this unexpected to you as well? Can you configure vite to prefer modules instead of main?

@dgeb
Copy link
Member

dgeb commented Mar 6, 2022

Fix included in v0.17.2

@towerhe
Copy link
Author

towerhe commented Mar 7, 2022

I am also a newbie of Vue + Vite community. By looking through the doc of vite and vitest, es modules should be used first.

After checking the deps of my project, I found some deps are distrubuted as commonjs modules e.g. @testing-library/vue. This commonjs deps maybe cause vite and vitest to change the resolving policy.

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

Successfully merging a pull request may close this issue.

2 participants