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

vanilla-extract/vite-plugin v4.0.4 does not work with custom TS paths/aliases in Astro #1336

Open
2 tasks done
tomahl opened this issue Mar 2, 2024 · 5 comments · May be fixed by #1395
Open
2 tasks done

vanilla-extract/vite-plugin v4.0.4 does not work with custom TS paths/aliases in Astro #1336

tomahl opened this issue Mar 2, 2024 · 5 comments · May be fixed by #1395
Labels
vite Issue related to vite

Comments

@tomahl
Copy link

tomahl commented Mar 2, 2024

Describe the bug

Hello there,

It seems like the latest vite-plugin version doesn't handle custom paths in Astro anymore. A clean install of Astro (v4.4.9), VE (v1.14.1) throws error on first run when using custom paths:

FailedToLoadModuleSSR Could not import file. Could not import @tokens/colors.

Worked fine with the previous version.

Reproduction

https://stackblitz.com/edit/withastro-astro-7asckv?file=tsconfig.json,src%2Fstyles%2Fglobal.css.ts,src%2Flayouts%2FLayout.astro

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (7) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.3 - /usr/local/bin/pnpm
  npmPackages:
    @vanilla-extract/css: ^1.14.1 => 1.14.1 
    @vanilla-extract/vite-plugin: ^4.0.4 => 4.0.4

Used Package Manager

npm

Logs

Error: Failed to load url @tokens/colors (resolved id: @tokens/colors) in /home/projects/withastro-astro-7asckv/src/styles/global.css.ts. Does the file exist?
    at loadAndTransform (/home/projects/withastro-astro-7asckv/node_modules/vite/dist/node/chunks/dep-jDlpJiMN.js:53650:21)
    at async ViteNodeServer._transformRequest (/home/projects/withastro-astro-7asckv/node_modules/vite-node/dist/server.mjs:426:16)
    at async ViteNodeServer._fetchModule (/home/projects/withastro-astro-7asckv/node_modules/vite-node/dist/server.mjs:396:17)
    at async ViteNodeRunnerWithContext.directRequest (/home/projects/withastro-astro-7asckv/node_modules/vite-node/dist/client.mjs:267:46)
    at async ViteNodeRunnerWithContext.cachedRequest (/home/projects/withastro-astro-7asckv/node_modules/vite-node/dist/client.mjs:206:14)
    at async ViteNodeRunnerWithContext.dependencyRequest (/home/projects/withastro-astro-7asckv/node_modules/vite-node/dist/client.mjs:250:12)
    at async eval (/home/projects/withastro-astro-7asckv/src/styles/global.css.ts:3:31)
    at async ViteNodeRunnerWithContext.runModule (/home/projects/withastro-astro-7asckv/node_modules/vite-node/dist/client.mjs:379:5)
    at async ViteNodeRunnerWithContext.directRequest (/home/projects/withastro-astro-7asckv/node_modules/vite-node/dist/client.mjs:363:5)
    at async ViteNodeRunnerWithContext.cachedRequest (/home/projects/withastro-astro-7asckv/node_modules/vite-node/dist/client.mjs:206:14)

Validations

@tomahl tomahl changed the title vanilla-extract/vite-plugin v4.0.4 does not work with TS paths/aliases in Astro vanilla-extract/vite-plugin v4.0.4 does not work with custom TS paths/aliases in Astro Mar 2, 2024
@askoufis
Copy link
Contributor

askoufis commented Mar 2, 2024

Seems like we've made our vite plugin too vite-specific.

const configFile = await loadConfigFromFile(
{
command: config.command,
mode: config.mode,
isSsrBuild: configEnv.isSsrBuild,
},
config.configFile,
);

We're attempting to load a vite config from a file, which doesn't exist in an astro project, so we end up with a null configFile, so we pass no vite plugins to our vite-node compiler, which causes this error (and likely other issues).

I suppose we have a few options:

  • Handle this case better. Either:
    • Fall back to our old behaviour of just reading in the existing plugins
    • Create our own loadConfigFromFile but for the astro config (is it just a dynamic import of the config + merging?)
  • Create a proper astro plugin

@tomahl
Copy link
Author

tomahl commented Mar 2, 2024

solidjs/solid-start is also moving away from vite.config in favour of app.config, mentioned here. Maybe something to consider when deciding the way forward.

@askoufis askoufis added vite Issue related to vite and removed pending triage labels Mar 4, 2024
@zhaohuanyuu
Copy link

Seems like we've made our vite plugin too vite-specific.

const configFile = await loadConfigFromFile(
{
command: config.command,
mode: config.mode,
isSsrBuild: configEnv.isSsrBuild,
},
config.configFile,
);

We're attempting to load a vite config from a file, which doesn't exist in an astro project, so we end up with a null configFile, so we pass no vite plugins to our vite-node compiler, which causes this error (and likely other issues).
I suppose we have a few options:

  • Handle this case better. Either:

    • Fall back to our old behaviour of just reading in the existing plugins
    • Create our own loadConfigFromFile but for the astro config (is it just a dynamic import of the config + merging?)
  • Create a proper astro plugin

same issue, Are there any plans that have been decided?

@askoufis
Copy link
Contributor

askoufis commented Mar 23, 2024

@tomahl This issue should be fixed by #1369. Please try out this snapshot version of the vite plugin if you get a chance: @vanilla-extract/vite-plugin@0.0.0-fix-vite-bugs-20240323060142.

@askoufis
Copy link
Contributor

@tomahl I just tested it with your reproduction and it seems the fix doesn't work. Need to dig into it further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vite Issue related to vite
Projects
None yet
3 participants