QwikDev / astro

Qwik + Astro integration
216 stars 13 forks source link

Qwik Integration not resolving correctly 'srcDir' from Astro config. #22

Closed iivvaannxx closed 1 year ago

iivvaannxx commented 1 year ago

Problem

The issue is actually very simple, I usually like to name my src dir source because I prefer it that way. Astro offers the possibility to change the source directory with its srcDir config property, and that's what i have:

export default defineConfig({

  integrations: [

    // ...
    qwikdev(),
    // ...
  ],

  srcDir: 'source',
  outDir: 'build',
})

But as soon as I try to start developing I face this error:

error   Qwik srcDir "/home/iivvaannxx/...myprojectroot.../src" not found.
Error: Qwik srcDir "/home/iivvaannxx/...myprojectroot.../src" not found.
    at Object.validateSource (file:///home/iivvaannxx/...myprojectroot.../node_modules/@builder.io/qwik/optimizer.mjs:1822:17)
    at async Context.buildStart (file:///home/iivvaannxx/...myprojectroot.../node_modules/@builder.io/qwik/optimizer.mjs:3377:7)
    at async Promise.all (index 3)
    at async hookParallel (file:///home/iivvaannxx/...myprojectroot.../node_modules/vite/dist/node/chunks/dep-bb8a8339.js:43927:9)
    at async Object.buildStart (file:///home/iivvaannxx/...myprojectroot.../node_modules/vite/dist/node/chunks/dep-bb8a8339.js:44251:13)
    at async file:///home/iivvaannxx/...myprojectroot.../node_modules/vite/dist/node/chunks/dep-bb8a8339.js:65315:13
    at async httpServer.listen (file:///home/iivvaannxx/...myprojectroot.../node_modules/vite/dist/node/chunks/dep-bb8a8339.js:65332:17)
error: script "dev" exited with code 1 (SIGHUP)

Additional Information

I tried hooking a console.log to see if the foillowing code (from the integration) correctly resolves the path:

code

And it actually does it resolve correctly to source so I guess the error is somewhere else.

Reproduction

Minimal Repro: https://stackblitz.com/edit/github-ubg8bv

A couple of things I noticed while setting up the reproduction example, which may be worth to look at are that, from a brand new Astro empty template and following the docs installation I got a random error:

Failed to load url fs-extra (resolved id: fs-extra) in /home/projects/github-ubg8bv/node_modules/@qwikdev/astro/src/index.ts. Does the file exist?

Which I fixed by manually installing fs-extra (I actually didn't need to do this in my local project so I don't understand why it happened edit: It just happened too). And, after creating a simple Counter component (like in the docs) I received also this error:

Error when evaluating SSR module /home/projects/github-ubg8bv/source/pages/index.astro: failed to import "/source/components/counter.tsx"
|- Error: Optimizer should replace all usages of $() with some special syntax. If you need to create a QRL manually, use inlinedQrl() instead.
    at $ (/home/projects/github-ubg8bv/node_modules/@builder.io/qwik/core.mjs:8508:15)
    at Proxy.component$ (/home/projects/github-ubg8bv/node_modules/@builder.io/qwik/core.mjs:8650:25)
    at eval (/home/projects/github-ubg8bv/source/components/counter.tsx:7:39)
    at async instantiateModule (/home/projects/github-ubg8bv/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:56104:9)

 error   Optimizer should replace all usages of $() with some special syntax. If you need to create a QRL manually, use inlinedQrl() instead.

This fixed itself after reloading the dev server (I think). After those I finally received the error I mention in this issue about the srcDir.

thejackshelton commented 1 year ago

Hey @iivvaannxx! Looks like @siguici might have fixed your issue here, if you could try 0.1.15 which was just released.

iivvaannxx commented 1 year ago

I can confirm that the project now can start the development server after astro dev. However, even though the pages seem to be correctly resolved it doesn’t seem to be the case with the Qwik generated files. See below:

IMG_0161

I can’t reopen the issue so probably someone should as it’s not totally fixed. Thanks for the initial fix @siguici! Also, now it seems everything works as it should without manually installing fs-extra.

The reproducible example is the same as the one of the original issue.

thejackshelton commented 1 year ago

can you send us a link of your stackblitz?

iivvaannxx commented 1 year ago

can you send us a link of your stackblitz?

Sorry, I said that it was the same as before but I just noticed that it didn’t get saved. I saved it: Link: https://stackblitz.com/edit/github-ubg8bv-n78dxb?file=package.json

Edit: It was still the same, don’t know why, anyways, I forked it and now it’s updated as the screenshot.

thejackshelton commented 1 year ago

0.1.18 should fix this

iivvaannxx commented 1 year ago

I did a quick test and indeed it's solved! Thanks both @siguici and @thejackshelton! I'll tell something if I run into some weird edge case or something.