QwikDev / astro

Qwik + Astro integration
216 stars 13 forks source link

Windows 10 build fails #29

Closed lovedder1995 closed 1 year ago

lovedder1995 commented 1 year ago

How to reproduce:

npm create astro@latest

Where should we create your new project?
  astro-app

How would you like to start your new project?
  Empty

Install dependencies?
  Yes

Do you plan to write TypeScript?
  No

Initialize a new git repository?
  Yes

cd astro-app

npx astro add @qwikdev/astro

create src/components/counter.jsx

import { component$, useSignal } from "@builder.io/qwik";

export const Counter = component$(() => {
  const counter = useSignal(0);

  return <button onClick$={() => counter.value++}>{counter.value}</button>;
});

edit src/pages/index.astro

---
import { Counter } from "../components/counter";
---

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
        <meta name="viewport" content="width=device-width" />
        <meta name="generator" content={Astro.generator} />
        <title>Astro</title>
    </head>
    <body>
        <h1>Astro.js - Qwik</h1>
        /* no hydration directive! */
        <Counter />
    </body>
</html>

npx astro build

 error   Path contains invalid characters: /C:/Users/user/astro-app/dist/
  File:
    C:\Users\user\astro-app\node_modules\fs-extra\lib\mkdirs\utils.js:16:21
  Code:
    15 |     if (pathHasInvalidWinCharacters) {
    > 16 |       const error = new Error(`Path contains invalid characters: ${pth}`)
         |                     ^
      17 |       error.code = 'EINVAL'
      18 |       throw error
      19 |     }
  Stacktrace:
Error: Path contains invalid characters: /C:/Users/user/astro-app/dist/
    at checkPath (C:\Users\user\astro-app\node_modules\fs-extra\lib\mkdirs\utils.js:16:21)
    at module.exports.makeDir (C:\Users\user\astro-app\node_modules\fs-extra\lib\mkdirs\make-dir.js:12:3)
    at Object.<anonymous> (C:\Users\user\astro-app\node_modules\universalify\index.js:18:45)
    at moveArtifacts (C:/Users/user/astro-app/node_modules/@qwikdev/astro/src/index.ts:114:39)
    at astro:build:done (C:/Users/user/astro-app/node_modules/@qwikdev/astro/src/index.ts:98:17)
    at async withTakingALongTimeMsg (file:///C:/Users/user/astro-app/node_modules/astro/dist/integrations/index.js:18:18)
    at async runHookBuildDone (file:///C:/Users/user/astro-app/node_modules/astro/dist/integrations/index.js:328:7)
    at async AstroBuilder.build (file:///C:/Users/user/astro-app/node_modules/astro/dist/core/build/index.js:145:5)
    at async AstroBuilder.run (file:///C:/Users/user/astro-app/node_modules/astro/dist/core/build/index.js:165:7)
    at async build (file:///C:/Users/user/astro-app/node_modules/astro/dist/core/build/index.js:44:3)

What I've found:

The error is caused when Qwik creates a /.tmp-{serial} folder in the root with the compiled code and then tries to move it to /dist

What I've tried to find the problem:

If I comment the function checkPath at node_modules\fs-extra\lib\mkdirs\make-dir.js:12:3 to skip the path validation a get this error:

ENOENT: no such file or directory, mkdir 'C:\C:\Users\user\astro-app\dist'

But from here I get confused, What could be causing the issue?

thejackshelton commented 1 year ago

I'm on it!

EDIT: was able to reproduce.

thejackshelton commented 1 year ago

Think I found the culprit here:

await moveArtifacts(
  tempDir,
  astroConfig.output === "server"
    ? astroConfig.build.client.pathname
    : astroConfig.outDir.pathname
);

Is logging out the C:\\ path when it shouldn't be.

The build works properly with this:

const outputPath = astroConfig.output === "server"
  ? astroConfig.build.client.pathname
  : astroConfig.outDir.pathname;
const normalizedPath = normalize(outputPath).replace('C:\\', ''); 
await moveArtifacts(tempDir, normalizedPath);
thejackshelton commented 1 year ago

Ok should be fixed in 0.1.19 @lovedder1995