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

fix: "Cannot read properties of undefined (reading 'get')" in ModuleLoader triggered by CSS import #19577

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dan-lee
Copy link

@dan-lee dan-lee commented Mar 5, 2025

Description

We are using Vite's loadConfigFromFile (runner mode) to load a TS file. We are aware that this is not 100% as intended, but it works fine and we do it at our own risk.
This TS file also loads a CSS file, which breaks the runner mode. A simple change, which I think makes sense anyway, fixes the problem.

To reproduce I created this StackBlitz: https://stackblitz.com/edit/vitejs-vite-yl98c3fh?file=package.json

You can pnpm load-with-css to see the problem:

❯ pnpm load-with-css

> [email protected] load-with-css /home/projects/vitejs-vite-yl98c3fh
> node load.js config-with-css.ts

failed to load config from /home/projects/vitejs-vite-yl98c3fh/config-with-css.ts
Error [TypeError]: Cannot read properties of undefined (reading 'get')
    at async ModuleLoader.import (https://vitejsviteyl98c3fh-vchr.w-credentialless-staticblitz.com/builtins.8cb5228f.js:154:2688)
    at async loadESM (https://vitejsviteyl98c3fh-vchr.w-credentialless-staticblitz.com/builtins.8cb5228f.js:184:541)
    at async handleMainPromise (https://vitejsviteyl98c3fh-vchr.w-credentialless-staticblitz.com/builtins.8cb5228f.js:165:296) {
  plugin: 'vite:css-post',
  id: '/home/projects/vitejs-vite-yl98c3fh/style.css',

I understand that you probably don't want to support the use case we have here and that it may break in the future, but I think the resulting fix still makes sense without all this context.

@dan-lee dan-lee changed the title Fix "Cannot read properties of undefined (reading 'get')" in ModuleLoader triggered by CSS import fix: "Cannot read properties of undefined (reading 'get')" in ModuleLoader triggered by CSS import Mar 5, 2025
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 this pull request may close these issues.

1 participant