QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.83k stars 1.31k forks source link

[🐞] Custom srcDir is not used with optimizer / vite plugins #3061

Closed adaliszk closed 1 year ago

adaliszk commented 1 year ago

Which component is affected?

Qwik Rollup / Qwik City / Vite plugin / Optimizer?

Describe the bug

When specifying a custom source directory, qwik city seems to find the routes, but qwik vite fails. I am setting the paths based on the configuration options:

qwikCity({ routesDir: './source/routes' })
qwikVite({ srcDir: './source' })

Alongside the tsconfig:

{
  // ...
  "includes": ["source"]
  // ...
}

Exact error thrown:

$ vite --open --mode ssr
error when starting dev server:
Error: Qwik srcDir "/home/projects/qwik-starter-hwtvkx/src" not found.
    at Object.validateSource (file:///home/projects/qwik-starter-hwtvkx/node_modules/@builder.io/qwik/optimizer.cjs:1080:19)
    at async Context.buildStart (file:///home/projects/qwik-starter-hwtvkx/node_modules/@builder.io/qwik/optimizer.cjs:2081:9)
    at async Promise.all (index 2)
    at async hookParallel (file://file:///home/projects/qwik-starter-hwtvkx/node_modules/vite/dist/node/chunks/dep-ae3fae1b.js:41341:9)
    at async Object.buildStart (file://file:///home/projects/qwik-starter-hwtvkx/node_modules/vite/dist/node/chunks/dep-ae3fae1b.js:41626:13)
    at async eval (file://file:///home/projects/qwik-starter-hwtvkx/node_modules/vite/dist/node/chunks/dep-ae3fae1b.js:61429:13)

Reproduction

https://stackblitz.com/edit/qwik-custom-srcdir?file=vite.config.ts

Steps to reproduce

Just configure qwikVite to have anything other than src as its srcDir property.

System Info

System:
    OS: Linux 4.17 Alpine Linux
    CPU: (12) x64 AMD Ryzen 5 3600 6-Core Processor
    Memory: 27.75 GB / 63.89 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
Binaries:
    Node: 18.12.1 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 9.1.2 - /usr/bin/npm
npmPackages:
    @builder.io/qwik: 0.19.0 => 0.19.0
    @builder.io/qwik-city: 0.3.0 => 0.3.0
    undici: 5.20.0 => 5.20.0
    vite: 4.1.1 => 4.1.1
Browsers:
    Chromium (110.0.1587.50)

Additional Information

I want to use this feature for two primary use cases:

  1. In my projects, I prefer source typed out to keep it aligned with the other top-level folder naming schemes
  2. When using it with storybooks, there is a requirement of having a root.tsx and I want to serve that from .storybook
stackblitz[bot] commented 1 year ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

zanettin commented 1 year ago

Hi @adaliszk qwikifier 👋 🙏 Is your use-case similar to this one? https://github.com/BuilderIO/qwik/issues/1885#issuecomment-1419686801

adaliszk commented 1 year ago

Thanks for the tip @zanettin!

Unfortunately, it looks like the issue is something else. I have updated the stackblitz link.

It seems to me that the compiler never gets to the state where it would have any parsing issues, it just does not find the src path as it does not exist, but it should have been overwritten with srcDir.

zanettin commented 1 year ago

Hi @adaliszk I need some more time to get into this. Imo we're loosing the srcDir here: https://github.com/BuilderIO/qwik/blob/main/packages/qwik/src/optimizer/src/plugins/vite.ts#L114-L126. But after fixing that, i get another error from qwik-city which still tries to resolve the routes from src 🤷

adaliszk commented 1 year ago

Yeah, I had run into that when I wanted to move the routes somewhere else. Somewhere it is more-less hardwired or missed in both of the plugins.

(added Qwik City to the affected components)