ElMassimo / iles

🏝 The joyful site generator
https://iles.pages.dev
MIT License
1.07k stars 31 forks source link

Version 0.8.0 won't run or build in Windows #161

Closed and-Zmei closed 2 years ago

and-Zmei commented 2 years ago

Description 📖

When updating to a new version, the generator does not start in development mode and does not build the project. The default project was launched via the pnpm create iles@next command. Screenshots below...

Reproduction 🐞

Please provide a link to a repo that can reproduce the problem you ran into.

Dependencies Info _Run `npx iles info` and `pnpm list` (or `npm list`) and provide the output:_ ``` D:\WORK\ANThill\temp\testIles>npx iles info iles v0.8.0 vite v3.0.0 D:\WORK\ANThill\temp\testIles>npm list testiles@0.0.0 D:\WORK\ANThill\temp\testIles ├── iles@0.8.0 ├── typescript@4.7.4 └── vue-tsc@0.38.5 ```

Screenshots 📷

image image

dhruvkb commented 2 years ago

I tried making a fresh iles app using

pnpm create iles@0.8.0

and was not able to reproduce your error. Maybe sharing your code could help with the reproduction process.

ElMassimo commented 2 years ago

Hi Andrey, thanks for reporting!

Based on the error screenshots you've attached, it's likely to be a Windows incompatibility, which has been a common source of problems in the past (#71 , #95, #107).

Help is appreciated, as it's tricky to ensure they are solved when working in a Unix-style OS.

ohuu commented 2 years ago

I hit this problem a couple days ago. I'm also on Windows. Happy to lend a hand. In the end I downgraded to 0.7.40 which works fine.

ElMassimo commented 2 years ago

A copy of the trace, and a copy of the part of the source code where the error occurs (by opening the chunk file inside iles in the last line of the trace) would definitely help to pinpoint where the error is 😃

ohuu commented 2 years ago

I just upgraded to 0.8.0 again and rebuilt the project using yarn build

Here is the trace I get.

build error:
 Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
    at new NodeError (node:internal/errors:387:5)
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1075:11)
    at defaultResolve (node:internal/modules/esm/resolve:1155:3)
    at nextResolve (node:internal/modules/esm/loader:173:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:852:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:439:18)
    at ESMLoader.import (node:internal/modules/esm/loader:536:22)
    at importModuleDynamically (node:internal/modules/esm/translators:110:35)
    at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:14)
    at renderPages (file:///C:/Users/Oliver/Workspace/duet3d-2/storefront-iles/node_modules/iles/dist/node/chunk-MT3B2PFP.js:19:25) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'

And here is what chunk-MT3B2PFP.js looks like:

import {
  getRoutesToRender
} from "./chunk-LXIIPGHJ.js";
import {
  withSpinner
} from "./chunk-ZYG3RLCI.js";

// src/node/build/render.ts
import { existsSync } from "fs";
import { join } from "pathe";
import { renderHeadToString } from "@vueuse/head";
import { renderers } from "@islands/prerender";
import { renderToString } from "@vue/server-renderer";
var commentsRegex = /<!--\[-->|<!--]-->|<!---->/g;
async function renderPages(config, islandsByPath, { clientResult }) {
  const appPath = ["js", "mjs", "cjs"].map((ext) => join(config.tempDir, `app.${ext}`)).find(existsSync);
  if (!appPath)
    throw new Error(`Could not find the SSR build for the app in ${config.tempDir}`);
  const { createApp } = await import(appPath);
  const routesToRender = await withSpinner("resolving static paths", async () => await getRoutesToRender(config, createApp));
  const clientChunks = clientResult.output;
  await withSpinner("rendering pages", async () => {
    for (const route of routesToRender)
      route.rendered = await renderPage(config, islandsByPath, clientChunks, route, createApp);
  });
  return { routesToRender };
}
async function renderPage(config, islandsByPath, clientChunks, route, createApp) {
  const { app, head } = await createApp({ routePath: route.path, ssrProps: route.ssrProps });
  let content = await renderToString(app, { islandsByPath, renderers });
  content = content.replace(commentsRegex, "");
  if (!route.outputFilename.endsWith(".html"))
    return content;
  const { headTags, htmlAttrs, bodyAttrs } = renderHeadToString(head);
  return `<!DOCTYPE html>
<html ${htmlAttrs}>
  <head>
    ${headTags}
    ${stylesheetTagsFrom(config, clientChunks)}
    ${await scriptTagsFrom(config, islandsByPath[route.path])}
  </head>
  <body ${bodyAttrs}>
    <div id="app">${content}</div>
  </body>
</html>`;
}
function stylesheetTagsFrom(config, clientChunks) {
  return clientChunks.filter((chunk) => chunk.type === "asset" && chunk.fileName.endsWith(".css")).map((chunk) => `<link rel="stylesheet" href="${config.base}${chunk.fileName}">`).join("\n");
}
async function scriptTagsFrom(config, islands) {
  const anySolid = islands == null ? void 0 : islands.some((island) => island.script.includes("@islands/hydration/solid"));
  if (!anySolid)
    return "";
  return "<script>window._$HY={events:[],completed:new WeakSet(),r:{}}<\/script>";
}

export {
  renderPages,
  renderPage
};

changing line 19 from

const appPath = ["js", "mjs", "cjs"].map((ext) => join(config.tempDir, `app.${ext}`)).find(existsSync);

to

const appPath = "file://" + ["js", "mjs", "cjs"].map((ext) => join(config.tempDir, `app.${ext}`)).find(existsSync);

seems to fix the problem.

ElMassimo commented 2 years ago

This is great @ohuu! I'll check to make sure file:// is cross-platform compatible, and cut a new release with this patch.

ElMassimo commented 2 years ago

Thanks @ohuu, released a patch in iles@0.8.1.

Please let me know if doesn't work as intended.

ohuu commented 2 years ago

Just tried it and it seems to be working well. Glad to be of help 👍