Skip to content

getViteConfig() throws an "ERR_MODULE_NOT_FOUND" error #4910

@screendriver

Description

@screendriver

What version of astro are you using?

1.3.1

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

I wanted to use Vitest together with Astro and saw that there is already an example directly within this repository that is based on pull request #4154. So I installed vitest and created a vitest.config.ts that looks like this:

/// <reference types="vitest" />
import { getViteConfig } from 'astro/config';

export default getViteConfig({
    test: {},
});

But when I try to execute vitest I'm getting the error

$ npx vitest
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/me/project/node_modules/astro/dist/core/config.js' imported from /Users/me/project/node_modules/astro/config.mjs

The issue is that https://github.com/withastro/astro/blob/24bad5a0ad6e3b64d9209aecffd8d0e9181135ad/packages/astro/config.mjs is importing ./dist/core/config.js which does not exist. The correct path would be ./dist/core/config/config.js. I tried to change that locally in my node_modules directory but then I'm getting

TypeError: Cannot read properties of undefined (reading 'config')
    at runHookConfigSetup (file:///Users/me/project/node_modules/astro/dist/integrations/index.js:26:37)

So the whole settings object here https://github.com/withastro/astro/blob/24bad5a0ad6e3b64d9209aecffd8d0e9181135ad/packages/astro/src/integrations/index.ts is undefined.

Link to Minimal Reproducible Example

https://stackblitz.com/github/withastro/astro/tree/latest/examples/with-vitest

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P5: urgentFix build-breaking bugs affecting most users, should be released ASAP (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions