question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Path handling during build with adapter-static

See original GitHub issue

Describe the bug Magic happens. Build fails with weird 404 when paths: { base: "/" } and there’s <a href="/">, and creates a directory buildfavicon.ico instead of nonexistent file build/favicon.ico.

Logs
yarn run v1.22.10
warning package.json: No license field
$ svelte-kit build
vite v2.2.4 building for production...
✓ 14 modules transformed.
.svelte/output/client/_app/manifest.json                    1.18kb
.svelte/output/client/_app/pages/index.svelte-31924b7e.js   0.41kb / brotli: 0.26kb
.svelte/output/client/_app/layout.svelte-f07a7e7f.js        0.49kb / brotli: 0.29kb
.svelte/output/client/_app/assets/start-a8cd1609.css        0.16kb / brotli: 0.10kb
.svelte/output/client/_app/error.svelte-6645eba8.js         1.19kb / brotli: 0.57kb
.svelte/output/client/_app/chunks/vendor-43cd886a.js        5.05kb / brotli: 1.98kb
.svelte/output/client/_app/start-fec3b019.js                16.00kb / brotli: 5.12kb
vite v2.2.4 building SSR bundle for production...
✓ 9 modules transformed.
.svelte/output/server/app.js   8.86kb

Run npm run preview to preview your production build locally.

> Using @sveltejs/adapter-static
> 404  (linked from /)
Error: 404  (linked from /)
    at error (file:///tmp/test/node_modules/@sveltejs/kit/dist/chunks/index5.js:92:11)
    at visit (file:///tmp/test/node_modules/@sveltejs/kit/dist/chunks/index5.js:159:5)
    at async visit (file:///tmp/test/node_modules/@sveltejs/kit/dist/chunks/index5.js:219:6)
    at async prerender (file:///tmp/test/node_modules/@sveltejs/kit/dist/chunks/index5.js:228:5)
    at async Object.prerender (file:///tmp/test/node_modules/@sveltejs/kit/dist/chunks/index5.js:295:5)
    at async adapt (/tmp/test/node_modules/@sveltejs/adapter-static/index.cjs:10:4)
    at async adapt (file:///tmp/test/node_modules/@sveltejs/kit/dist/chunks/index5.js:321:2)
    at async file:///tmp/test/node_modules/@sveltejs/kit/dist/cli.js:590:5
error Command failed with exit code 1.

To Reproduce

$ npm init svelte@next test # create-svelte version 2.0.0-next.64, choose skeleton, no, no, no
$ cd test
$ yarn add -D @sveltejs/adapter-static@next # @next doesn't work, have to edit package.json manually then `yarn` to sync
$ cat > svelte.config.cjs
module.exports = {
  kit: {
    target: "#svelte",
    paths: { base: "/" },
    adapter: require("@sveltejs/adapter-static")(),
  },
};
$ yarn build # fails, HOWEVER: dir buildfavicon.ico/ is created !
$ # now remove favicon link from src/app.html
$ yarn build # builds ok
$ cat > src/routes/index.svelte
<a href="/">home</a>
$ yarn build # the error above

Expected behavior Build correctly, application should assume that everything is served at /

Information about your SvelteKit Installation:

Diagnostics

npx envinfo --system --npmPackages svelte,@sveltejs/kit,vite,@sveltejs/adapter-static --binaries --browsers

  System:
    OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i3-3110M CPU @ 2.40GHz
    Memory: 291.48 MB / 7.35 GB
    Container: Yes
    Shell: 3.1.0 - /usr/bin/fish
  Binaries:
    Node: 14.16.0 - ~/.local/bin/node
    Yarn: 1.22.10 - ~/.local/bin/yarn
    npm: 7.6.3 - ~/.local/bin/npm
  Browsers:
    Chromium: 90.0.4430.93
    Firefox: 88.0
  npmPackages:
    @sveltejs/adapter-static: next => 1.0.0-next.7 
    @sveltejs/kit: next => 1.0.0-next.96 
    svelte: ^3.34.0 => 3.38.2 
    vite: ^2.2.3 => 2.2.4 

Severity After removing the paths config key everything works correctly, but docs say that base should be root-relative, but the default actually isn’t ('' from docs, idk where to look into code). So this is quite a bad footgun.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
jakemovescommented, May 7, 2021

Didn’t mean to steer this in the wrong direction, was just trying to substantiate the issue and leave a breadcrumb for any other new users running into this.

1reaction
Rich-Harriscommented, Apr 23, 2022

In the current version, base: '/' will fail with an error:

config.kit.paths.base option must be a root-relative path that starts but doesn’t end with ‘/’. See https://kit.svelte.dev/docs/configuration#paths

Opened #4713 to clarify that, but I’ll close this first since / is already disallowed.

There’s a lot of other noise in this thread — if there are other issues beyond the OP they’ll need to be opened separately

Read more comments on GitHub >

github_iconTop Results From Across the Web

@sveltejs/adapter-static - npm
@sveltejs/adapter-static. Adapter for SvelteKit apps that prerenders your entire site as a collection of static files.
Read more >
SvelteKit with adapter-static throws an error > 404 at <img ...
The solution is to put assets not into the root , but into the static folder! So media folder for example should be...
Read more >
Adapters • Docs • SvelteKit
Most adapters will generate static HTML for any prerenderable pages of your site. In some cases, your entire app might be prerenderable, in...
Read more >
Deploying a Static Site - Vite
The vite preview command will boot up a local static web server that serves the ... It's an easy way to check if...
Read more >
@sveltejs/adapter-static | Yarn - Package Manager
Adapter for SvelteKit apps that prerenders your entire site as a collection of static files. If you'd like to prerender only some pages,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found