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

Cannot import @auth/sveltekit in Vitest #12290

Open
Stadly opened this issue Nov 25, 2024 · 0 comments
Open

Cannot import @auth/sveltekit in Vitest #12290

Stadly opened this issue Nov 25, 2024 · 0 comments
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@Stadly
Copy link

Stadly commented Nov 25, 2024

Environment

  System:
    OS: Linux 6.5 Ubuntu 20.04.6 LTS (Focal Fossa)
    CPU: (2) x64 Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
    Memory: 5.56 GB / 7.74 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 20.17.0 - ~/nvm/current/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 10.8.2 - ~/nvm/current/bin/npm
    pnpm: 9.11.0 - ~/nvm/current/bin/pnpm
  npmPackages:
    @auth/sveltekit: latest => 1.7.4 
    @sveltejs/kit: 2.5.7 => 2.5.7 
    svelte: 4.2.19 => 4.2.19 

Reproduction URL

https://github.com/Stadly/reproduction/tree/auth.js/sveltekit-vitest-failing

Describe the issue

When using browser resolution, which is the way to go, Vitest fails when importing @auth/sveltekit:

SyntaxError: Named export 'jsx' not found. The requested module 'preact/jsx-runtime' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'preact/jsx-runtime';
const { jsx: _jsx, jsxs: _jsxs } = pkg;

 ❯ node_modules/@auth/sveltekit/dist/env.js:1:31
      1| import { setEnvDefaults as coreSetEnvDefaults, skipCSRFCheck } from "@auth/core";
       |                               ^
      2| import { dev, building } from "$app/environment";
      3| import { base } from "$app/paths";

How to reproduce

  1. Set up Vitest and Svelte Testing Library
  2. Set up Auth.js
  3. Create a test importing @auth/sveltekit
import { SvelteKitAuth } from "@auth/sveltekit"; // <-- This fails!
import { it } from "vitest";

it("test auth in some way", () => {
   // ... 
});

With the reproduction URL, just run npm run i && npm run test to see the issue.

Expected behavior

Importing @auth/sveltekit should not cause any issues with Vitest.

@Stadly Stadly added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Nov 25, 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 triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

1 participant