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.

adapter-node fails and logs a 404 when it encounters an asset with a protocol-relative url

See original GitHub issue

Describe the bug

When an asset has an url starting with “//”, adapter-node fails and logs a 404 error.

Logs Server logs:

> Using @sveltejs/adapter-node
> 404 //localhost/svelte-welcome.png (linked from /)
Error: 404 //localhost/svelte-welcome.png (linked from /)

(more details in the “Stacktrace” part)

To Reproduce

An example is here: https://github.com/SiegfriedEhret/svelte-404-repro

Here we go for the steps:

Run the following:

npm init svelte@next my-app
cd my-app
npm install
npm i -D @sveltejs/adapter-node@next

Follow the docs to update the svelte config and add the adapter:

// svelte.config.js
import adapter from '@sveltejs/adapter-node';

export default {
	kit: {
		adapter: adapter({
			// default options are shown
			out: 'build'
		})
	}
};

(⚠️ this is the important part) Modify src/routes/index.svelte and replace:

<img src="svelte-welcome.png" alt="Welcome" />

With:

<img src="//localhost/svelte-welcome.png" alt="Welcome" />

Run:

npm run build

And that is where the 404 is logged.

Expected behavior

First, I’d love to see a warning instead of an error. Then, if we have a warning, it should not stop on the first relevant asset (it currently does).

Stacktraces If you have a stack trace to include, we recommend putting inside a <details> block for the sake of the thread’s readability:

Stack trace
❯ npm run build

> ~TODO~@0.0.1 build
> svelte-kit build

vite v2.3.3 building for production...
✓ 34 modules transformed.
.svelte-kit/output/client/_app/assets/svelte-logo.87df40b8.svg                           1.85kb
.svelte-kit/output/client/_app/assets/fira-mono-cyrillic-400-normal.046b609f.woff2       9.08kb
.svelte-kit/output/client/_app/assets/fira-mono-greek-ext-400-normal.8659ae46.woff2      7.85kb
.svelte-kit/output/client/_app/assets/fira-mono-greek-400-normal.1f8b3a07.woff2          10.48kb
.svelte-kit/output/client/_app/assets/fira-mono-cyrillic-ext-400-normal.b3140dd3.woff2   16.11kb
.svelte-kit/output/client/_app/assets/fira-mono-latin-ext-400-normal.b6331a25.woff2      11.84kb
.svelte-kit/output/client/_app/assets/fira-mono-latin-400-normal.a2f9dbe8.woff2          16.44kb
.svelte-kit/output/client/_app/assets/fira-mono-all-400-normal.0d19eb5d.woff             75.54kb
.svelte-kit/output/client/_app/manifest.json                                             2.43kb
.svelte-kit/output/client/_app/error.svelte-9614ef2b.js                                  1.19kb / brotli: 0.57kb
.svelte-kit/output/client/_app/pages/index.svelte-cc0dcee2.js                            4.07kb / brotli: 1.45kb
.svelte-kit/output/client/_app/pages/__layout.svelte-176944a0.js                         4.62kb / brotli: 1.51kb
.svelte-kit/output/client/_app/pages/about.svelte-f4f53345.js                            2.39kb / brotli: 0.90kb
.svelte-kit/output/client/_app/assets/start-a8cd1609.css                                 0.16kb / brotli: 0.10kb
.svelte-kit/output/client/_app/pages/todos/index.svelte-d3b5a46f.js                      6.12kb / brotli: 2.11kb
.svelte-kit/output/client/_app/assets/pages/__layout.svelte-d4883a00.css                 5.04kb / brotli: 1.35kb
.svelte-kit/output/client/_app/assets/pages/about.svelte-4db5be0d.css                    0.11kb / brotli: 0.07kb
.svelte-kit/output/client/_app/assets/pages/index.svelte-078f1a0b.css                    1.35kb / brotli: 0.36kb
.svelte-kit/output/client/_app/assets/pages/todos/index.svelte-ef0435f2.css              3.71kb / brotli: 0.86kb
.svelte-kit/output/client/_app/chunks/vendor-2f7c43bc.js                                 11.48kb / brotli: 4.54kb
.svelte-kit/output/client/_app/start-b2a68348.js                                         17.76kb / brotli: 5.62kb
vite v2.3.3 building SSR bundle for production...
transforming (22) .svelte-kit/build/runtime/app/env.js"scale" is imported from external module "svelte/transition" but never used in "src/routes/todos/index.svelte".
"flip" is imported from external module "svelte/animate" but never used in "src/routes/todos/index.svelte".
✓ 27 modules transformed.
.svelte-kit/output/server/app.js   64.27kb

Run npm run preview to preview your production build locally.

> Using @sveltejs/adapter-node
> 404 //localhost/svelte-welcome.png (linked from /)
Error: 404 //localhost/svelte-welcome.png (linked from /)
    at error (file:///Users/siegfried/dev/my-app/node_modules/@sveltejs/kit/dist/chunks/index5.js:93:11)
    at visit (file:///Users/siegfried/dev/my-app/node_modules/@sveltejs/kit/dist/chunks/index5.js:160:5)
    at async visit (file:///Users/siegfried/dev/my-app/node_modules/@sveltejs/kit/dist/chunks/index5.js:220:6)
    at async prerender (file:///Users/siegfried/dev/my-app/node_modules/@sveltejs/kit/dist/chunks/index5.js:229:5)
    at async Object.prerender (file:///Users/siegfried/dev/my-app/node_modules/@sveltejs/kit/dist/chunks/index5.js:296:5)
    at async adapt (file:///Users/siegfried/dev/my-app/node_modules/@sveltejs/adapter-node/index.js:28:4)
    at async adapt (file:///Users/siegfried/dev/my-app/node_modules/@sveltejs/kit/dist/chunks/index5.js:322:2)
    at async file:///Users/siegfried/dev/my-app/node_modules/@sveltejs/kit/dist/cli.js:616:5

Information about your SvelteKit Installation:

Diagnostics
  • The output of npx envinfo --system --npmPackages svelte,@sveltejs/kit,vite --binaries --browsers
  System:
    OS: macOS 11.3.1
    CPU: (8) x64 Intel(R) Core(TM) i5-1030NG7 CPU @ 1.10GHz
    Memory: 20.20 MB / 16.00 GB
    Shell: 3.2.2 - /usr/local/bin/fish
  Binaries:
    Node: 16.1.0 - ~/.asdf/installs/nodejs/16.1.0/bin/node
    npm: 7.14.0 - ~/.asdf/installs/nodejs/16.1.0/.npm/bin/npm
  Browsers:
    Firefox Developer Edition: 89.0
    Safari: 14.1
  npmPackages:
    @sveltejs/kit: next => 1.0.0-next.109
    svelte: ^3.34.0 => 3.38.2
  • Your browser

Firefox 89.0b15

  • Your adapter (e.g. Node, static, Vercel, Begin, etc…)

Node

Severity

On the protocol-relative url, here are 2 interesting readings:

Even if discouraged, it is still around.

In the end, not severe. I just have to go through all my content to force https 😅!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
babichjacobcommented, May 24, 2021

This is a (potential) issue with the prerendering functionality, so it’s best represented by the static adapter label. (Maybe we can change that)

@babichjacob You are right, it should be //domain.tld/svelte-welcome.png. I have updated the issue description and the example repository. Thank you.

Could I perhaps argue that protocol-aware links aren’t really useful anymore, or at least not in a modern framework like SvelteKit given previous decisions about what legacy things not to support? HTTPS should be an always thing now—I think. So write your links with the appropriate https:// prefix and in its current state the prerenderer will recognize them as external rather than erroring about not being able to find them internally.

0reactions
SiegfriedEhretcommented, Feb 23, 2022

Hello, I just tried again and it is working. Aaaand maybe it was a problem between keyboard and chair after all, because the //localhost/... could not work, I needed //localhost:3000/.... Sorry! xoxo

Read more comments on GitHub >

github_iconTop Results From Across the Web

adapter-node doesn't work correctly with paths.base #3726
the problem now is that the browser is not able to fetch the files in client and static . The node server returns...
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 >
Removed malware from wordpress site, now getting strange ...
Removed malware from wordpress site, now getting strange php urls and 404 errors ... It also says “A 404 not found error was...
Read more >
How To Find & Fix 404 Errors On Your Website | Matthew Edgar
The first step to fixing a 404 error is finding the 404 not-found error. Once found, you can begin fixing the 404 not-found...
Read more >
How To Properly Serve 404 Errors on SPAs (with SEO in Mind)
Out of the box, 404 error pages in SPAs don't work properly, creating problems for SEO. Here we'll review the pros and cons...
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