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

v0.32.0 Unable to resolve sveltekit environment module alias #3540

Closed
6 tasks done
cesarnml opened this issue Jun 7, 2023 · 1 comment · Fixed by #3544
Closed
6 tasks done

v0.32.0 Unable to resolve sveltekit environment module alias #3540

cesarnml opened this issue Jun 7, 2023 · 1 comment · Fixed by #3544
Milestone

Comments

@cesarnml
Copy link

cesarnml commented Jun 7, 2023

Describe the bug

On upgrading to vitest@0.32.0 tests are unable to resolve sveltekit's environment module alias ($env). There is no error when running tests on vitest@0.31.4.

Is there something wrong in my configuration after upgrading to 0.32.0? No other changes were made in the linked repo aside from upgrading the vitest packages version.

 FAIL  src/routes/api/wakatime/current/summaries/server.spec.ts [ src/routes/api/wakatime/current/summaries/server.spec.ts ]
Error: Cannot find module '$env/static/private'.

- If you rely on tsconfig.json to resolve modules, please install "vite-tsconfig-paths" plugin to handle module resolution.
 - Make sure you don't have relative aliases in your Vitest config. Use absolute paths instead. Read more: https://vitest.dev/guide/common-errors
 ❯ src/routes/api/wakatime/current/summaries/+server.ts:1:31
      1| import { WAKA_API_KEY } from '$env/static/private'
       |                               ^
      2| import { BaseUrl, RestResource, WakaApiRange } from '$lib/constants'
      3| import type { SummariesResult } from '$src/types/wakatime'
 ❯ src/routes/api/wakatime/current/summaries/server.spec.ts:2:31

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: {
  "code": "ERR_MODULE_NOT_FOUND",
}

Repository With Import Error:
https://github.com/cesarnml/waka-shortcut-time-stats/tree/cesar/vitest-0.32.0-sveltekit-bug

Main Branch runs on vitest 0.31.4 (no import error):
https://github.com/cesarnml/waka-shortcut-time-stats/tree/main

Reproduction

  1. Run a test on a component/function that imports sveltekit's built-in environment module ($env = https://kit.svelte.dev/docs/modules)

System Info

System:
    OS: macOS 13.4
    CPU: (8) arm64 Apple M1
    Memory: 83.20 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
    Watchman: 2023.05.22.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 114.1.52.117
    Chrome: 113.0.5672.126
    Chrome Canary: 116.0.5817.0
    Firefox: 101.0
    Firefox Developer Edition: 114.0
    Firefox Nightly: 111.0a1
    Safari: 16.5
  npmPackages:
    @vitest/coverage-c8: 0.32.0 => 0.32.0 
    @vitest/coverage-istanbul: 0.32.0 => 0.32.0 
    @vitest/coverage-v8: 0.32.0 => 0.32.0 
    @vitest/ui: 0.32.0 => 0.32.0 
    vite: 4.3.9 => 4.3.9 
    vitest: 0.32.0 => 0.32.0

Used Package Manager

pnpm

Validations

@cesarnml cesarnml changed the title v0.32.0 Unable to resolve sveltekit module aliases v0.32.0 Unable to resolve sveltekit environment module alias Jun 7, 2023
@jamesbirtles
Copy link

jamesbirtles commented Jun 7, 2023

I was just typing out this exact same issue!
Here's the reproduction I was going to add to it https://github.com/jamesbirtles/bug-vitest-0-32-sveltekit

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

Successfully merging a pull request may close this issue.

3 participants