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

Issue importing @auth/core when using Jest #6822

Closed
ivoilic opened this issue Feb 25, 2023 · 1 comment
Closed

Issue importing @auth/core when using Jest #6822

ivoilic opened this issue Feb 25, 2023 · 1 comment
Labels
triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@ivoilic
Copy link

ivoilic commented Feb 25, 2023

Environment

System:
OS: macOS 13.2.1
CPU: (12) x64 Apple M2 Pro
Memory: 302.45 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 19.6.0 - ~/.nvm/versions/node/v19.6.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v19.6.0/bin/yarn
npm: 9.4.0 - ~/.nvm/versions/node/v19.6.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Browsers:
Chrome: 110.0.5481.100
Firefox: 98.0.2
Safari: 16.3
Packages:
@auth/core: 0.5.0

Reproduction URL

https://github.com/yusukebe/jest-authjs

Describe the issue

Importing @auth/core while running Jest fails. This is not the case with other npm modules. When importing anything from @auth/core I get the following error in Jest: Cannot find module '@auth/core/providers/github' I encountered this while writing Auth.js Middlware for Hono: honojs/middleware#52

How to reproduce

Checkout this PR: honojs/middleware#52

  1. yarn install
  2. yarn build
  3. cd packages/authjs-server
  4. jest

The author of Hono also created this more cut down demo: https://github.com/yusukebe/jest-authjs

Expected behavior

When running tests with Jest imports from @auth/core should import the same as other packages

@ivoilic ivoilic added the triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. label Feb 25, 2023
@balazsorban44
Copy link
Member

This is because @auth/core is published as ESM only, and Jest's ESM support is a bit funky right now.

I published your reproduction with some changes, which should make it pass the tests:

https://github.com/balazsorban44/authjs-6822

image

Notable additions:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

2 participants