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

Prerenderer don't follow symbolic link in assets folder #4709

Closed
iacore opened this issue Apr 23, 2022 · 1 comment · Fixed by #5089
Closed

Prerenderer don't follow symbolic link in assets folder #4709

iacore opened this issue Apr 23, 2022 · 1 comment · Fixed by #5089
Milestone

Comments

@iacore
Copy link

iacore commented Apr 23, 2022

Describe the bug

If prerendered page reference assets through a symbolic link, then it will not be accessible on svelte-kit build.

Reproduction

https://github.com/locriacyber/debug-svelte-symbolic

Note:

  • static/data is symbolic link to data
  • The website works fine in yarn dev
  • But it breaks with yarn build

Logs

> yarn build
yarn run v1.22.18
warning package.json: No license field
$ svelte-kit build
vite v2.9.5 building for production...
✓ 13 modules transformed.
.svelte-kit/output/client/_app/manifest.json                    1.14 KiB
.svelte-kit/output/client/_app/start-32c0b608.js                23.10 KiB / gzip: 8.67 KiB
.svelte-kit/output/client/_app/layout.svelte-23d0f029.js        0.53 KiB / gzip: 0.35 KiB
.svelte-kit/output/client/_app/error.svelte-bb9909e1.js         1.56 KiB / gzip: 0.74 KiB
.svelte-kit/output/client/_app/pages/index.svelte-8781c221.js   0.48 KiB / gzip: 0.33 KiB
.svelte-kit/output/client/_app/chunks/index-dd45c2ae.js         6.83 KiB / gzip: 2.79 KiB
vite v2.9.5 building SSR bundle for production...
✓ 11 modules transformed.
Generated an empty chunk: "hooks"
.svelte-kit/output/server/manifest.json                        1.09 KiB
.svelte-kit/output/server/index.js                             75.42 KiB
.svelte-kit/output/server/entries/fallbacks/layout.svelte.js   0.24 KiB
.svelte-kit/output/server/entries/fallbacks/error.svelte.js    0.72 KiB
.svelte-kit/output/server/entries/pages/index.svelte.js        0.28 KiB
.svelte-kit/output/server/chunks/index-2dc61825.js             2.29 KiB
.svelte-kit/output/server/chunks/hooks-1c45ba0b.js             0.00 KiB
> 404 /data/home.html (linked from /)

Severity

annoyance, workaround complicated

Workaround

Use the following file as hooks.ts

import type { Handle } from "@sveltejs/kit"
import * as fs from "fs/promises"
import * as path from "path"

// Workaround for https://github.com/sveltejs/kit/issues/4709
export const handle: Handle = async function({ event, resolve: res }) {
  if (event.url.pathname.startsWith("/data/")) {
    const relpath = event.url.pathname.slice("/data/".length)
    return new Response(await fs.readFile(path.join(await find_project_root(), "../data", relpath)))
  }

  const response = await res(event)
  return response
}

async function find_project_root(): Promise<string> {
    let patha = path.resolve(".")
    while (!(await fs.readdir(patha)).indexOf("package.json")) {
        const pathb = path.join(patha, "..")
        if (pathb == patha) throw Error("Cannot find project root")
        patha = pathb
    }
    return patha
}
@iacore iacore changed the title adapter-static don't follow symbolic link in assets folder Prerenderer don't follow symbolic link in assets folder Apr 23, 2022
@Rich-Harris Rich-Harris added this to the 1.0 milestone Apr 23, 2022
@gaarf
Copy link
Contributor

gaarf commented May 25, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants