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

Getting 404 error during "npm run build", but not "npm run dev" (simple static adapter website) #2962

Closed
BobSchnatt opened this issue Dec 1, 2021 · 24 comments · May be fixed by naiba4/kit#1
Labels
help wanted PRs welcomed. The implementation details are unlikely to cause debate p3-edge-case SvelteKit cannot be used in an uncommon way pkg:adapter-static

Comments

@BobSchnatt
Copy link

Describe the bug

After a recent npm update (which I'm assuming updated Svelte, but correct me if I'm wrong), I've started getting a 404 error when attempting to do a release build. It doesn't happen when I do a preview build (see attached image).

My site is a very simple static webpage (using adapter-static). No stub routing, no spaces in image filenames, etc.

Screenshot 2021-12-01 154845

Reproduction

See files I've attached here. Since this error occurs at build time (and not during website usage), I'm not sure how to respond to this.

My website is proprietary and thus not on Github. I can send the full repository to a Svelte maintainer via ProtonMail if necessary. Please advise.

tsconfig json

svelte config js

package json

jsconfig json

Logs

I'm not sure what logs to include. If you need any, please advise. Thank you in advance for your help...

System Info

System:
    OS: Linux 5.10 Ubuntu 18.04.6 LTS (Bionic Beaver)
    CPU: (4) x64 Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz
    Memory: 3.90 GB / 6.08 GB
    Container: Yes
    Shell: 4.4.20 - /bin/bash
  Binaries:
    Node: 16.4.1 - ~/.nvs/node/16.4.1/x64/bin/node
    npm: 7.18.1 - ~/.nvs/node/16.4.1/x64/bin/npm
  npmPackages:
    @sveltejs/adapter-static: ^1.0.0-next.13 => 1.0.0-next.21
    @sveltejs/kit: next => 1.0.0-next.201
    svelte: ^3.34.0 => 3.44.2

Severity

blocking an upgrade

Additional Information

No response

@BobSchnatt
Copy link
Author

An addendum: I'm not using TypeScript, so the config file for that is unused (?)

@bluwy
Copy link
Member

bluwy commented Dec 4, 2021

There's not much info here for us to debug, please provide a repro on github or stackblitz. The repro should be minimal and created from scratch so proprietary shouldn't be an issue, it would also help narrow the cause too.

@BobSchnatt
Copy link
Author

Working on it...

@BobSchnatt
Copy link
Author

Ok, I built a demo test site which very closely mirrors my actual site. It has all the basic functionality: all the routes, the image gallery, the nav bar, the header and footer that appears on every page, the ability to make the footer disappear when you click on it, etc. Page for page and feature for feature, it's the same website, just with my company stuff left out (and it uses smaller pages - fewer paragraphs and images). And I can use "npm run build" without error.

The only way I can help you resolve this is to send you both my test site repository (zipped up) and my official repository so you can compare. So, my question is: what non-identifying files & folders can I send you from my official repository that you can use to do this comparison?

Clearly, something changed and/or got corrupted at some point in my official build setup. I'm way too dumb to be able to figure that out, so you're gonna have to do it for me! In the meantime, I'm gonna make a copy of the demo site folder and copy my REAL files into it and see if I can resolve the problem on my end that way.

Thanks

@BobSchnatt
Copy link
Author

One thing I've found is my site builds fine when I use adapter-auto, but not adapter-static. Pulling my hair out...

@BobSchnatt
Copy link
Author

BobSchnatt commented Dec 6, 2021

Ok, I was able to finally reproduce the problem. When I changed the demo site's adapter to adapter-static, the problem reared it's head. Included below. (I omitted the node_modules directory, but kept everything else.) Let me know if you need anything else. Thanks...
DemoSite.zip

@nikitaiavdeev
Copy link

nikitaiavdeev commented Dec 6, 2021

I had an identical issue. I found that it's happening when your routing folder doesn't have index.svelte.
You could fix your error by creating /Support/FAQ/index.svelte.

@BobSchnatt
Copy link
Author

Thanks, but I have other routes that work (or, at least, used to work) without index.svelte. My website ran fine for several months, and then builds stopped working for some reason, even though I only make cosmetic changes for the most part. Is index.svelte now a requirement?

@bluwy bluwy added p3-edge-case SvelteKit cannot be used in an uncommon way pkg:adapter-static and removed awaiting submitter labels Dec 6, 2021
@bluwy
Copy link
Member

bluwy commented Dec 6, 2021

The index.svelte file shouldn't be necessary, but I don't remember anything that would cause that behaviour. I'll take a deeper look at this tomorrow, but since you've mentioned that this only happen after an update in sveltekit/static, you can also try downgrading them and see which version breaks it. The changelog may help with it too.

@nikitaiavdeev
Copy link

nikitaiavdeev commented Dec 6, 2021

Thanks, but I have other routes that work (or, at least, used to work) without index.svelte. My website ran fine for several months, and then builds stopped working for some reason, even though I only make cosmetic changes for the most part. Is index.svelte now a requirement?

Yes, my project worked fine without index.svelte before as well. Unfortunately, I haven't noticed from what sveltekit version it happened.

@BobSchnatt
Copy link
Author

Ok, I downgraded SvelteKit to "1.0.0-next.195" and that fixed the problem, so I started incrementing upwards, and the problem reappeared in "1.0.0-next.200", so the "200" update broke something (or exposed a flaw in my website)...

@BobSchnatt
Copy link
Author

Ok, I downgraded SvelteKit to "1.0.0-next.195" and that fixed the problem, so I started incrementing upwards, and the problem reappeared in "1.0.0-next.200", so the "200" update broke something (or exposed a flaw in my website)...

I downgraded to 1.0.0-next.199 in my package.json file in my official website configuration and was able to do an official release build. Yay!

@bluwy
Copy link
Member

bluwy commented Dec 8, 2021

Sorry, got a lot busy recently, but thanks for tracking this down! That means something in v200 failed, which is likely #2832. If someone wants to help out, feel free to debug that PR.

@joenano
Copy link

joenano commented Dec 9, 2021

The path to static files in release build with adapter-static has been an unresolved issue for at least 50 versions it seems, bizarre.

@daevid66
Copy link

I also got problems after #2832, in my case it is a combination of the following:

  • my static site is not hosted the root of my domain, let's say it in www.domain.com/test. I have added /test as base path and page/asset paths in svelte-config.
  • I have a 302 redirect that need to point to /test/page1
  • After updating svelte-kit (including follow redirects when prerendering #2832) the build process tries to crawl the redirected url (/test/page1), but it cannot find it, since it's actually positioned at /page1 during the build process.

I added a work-around, by adding an extra empty route at /test/page1, which 'works' but it would be preferable if either:

  1. Svelte-kit accounts for base path when crawling redirects.
  2. You can somehow flag that you don't want to crawl your redirects.

danielnaab added a commit to 18F/federal-carbon-footprint that referenced this issue Dec 17, 2021
@mhkeller
Copy link

Same here. I downgraded to "@sveltejs/kit": "1.0.0-next.200" and also "@sveltejs/adapter-static": "1.0.0-next.22" and exports started working properly again.

I made a repro on this branch. npm run build completes without an error but it fails to build three routes. In the docs folder there should be an examples folder containing three pages: Line, CirclePackNested and SyncedBrush. Instead there is no examples folder.

@gkankanh
Copy link

gkankanh commented Mar 13, 2022

I get the same error too on any image links.
svelte-kit/output/server/manifest.json 1.26 KiB
.svelte-kit/output/server/index.js 64.88 KiB
.svelte-kit/output/server/entries/pages/__layout.svelte.js 24.62 KiB
.svelte-kit/output/server/entries/fallbacks/error.svelte.js 0.72 KiB
.svelte-kit/output/server/entries/pages/index.svelte.js 8.06 KiB
.svelte-kit/output/server/entries/pages/about.svelte.js 1.30 KiB
.svelte-kit/output/server/chunks/index-d82f9bb9.js 6.71 KiB

404 /src/content/images/home/Cloud.svg (linked from /)
at file:///D:/gopal/projects/svcrrs/node_modules/@sveltejs/kit/dist/chunks/index2.js:975:11
at save (file:///D:/gopal/projects/svcrrs/node_modules/@sveltejs/kit/dist/chunks/index2.js:1194:4)
at visit (file:///D:/gopal/projects/svcrrs/node_modules/@sveltejs/kit/dist/chunks/index2.js:1085:3)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

svelete-config.js

import sveltePreprocess from 'svelte-preprocess'
import path from 'path'
import adapter from '@sveltejs/adapter-static'
import { defineConfig, searchForWorkspaceRoot } from 'vite'
//import scss from 'svelte-preprocess'
//import node from '@sveltejs/adapter-node'

/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess for more information about preprocessors
preprocess: [

	// Auto-preprocess mode - no need for specifying standlone SCSS preprocesors, etc.
	// https://github.com/sveltejs/svelte-preprocess/blob/main/docs/preprocessing.md#auto-preprocessing
	// sveltePreprocess()
	sveltePreprocess({
		defaults: {
			// Remove the need to add the `lang=` tag for each type.
			// Not recommended because not all tooling understands this
			style: 'scss',
			script: 'typescript',
			markup: 'html'
		},
		scss: {
			// We can use a path relative to the root because svelte-preprocess automatically adds
			// it to `includePaths` if none is defined.
			// This allows us to use the variables in our components - don't turn on unless really need it
			// prependData: `@import 'src/styles/_variables.scss';`,

			// Docs say renderSync is faster for Dart Sass which I am using
			// https://github.com/sveltejs/svelte-preprocess/blob/main/docs/preprocessing.md#scss-sass
			renderSync: true,

			// Dart Sass recognizes 'expanded' and 'compressed'
			outputStyle: 'expanded'
		}
	}),

	// Standalone preprocessors go here for customized configurations.
	// https://github.com/sveltejs/svelte-preprocess/blob/main/docs/preprocessing.md#stand-alone-processors
	// scss(),
],

kit: {
	// This is the static adapter
	adapter: adapter({
		pages:'build',
		assets: 'build',
		fallback: 'app.html'
	  }),
	  files: {
		template: 'src/app.html'
	  },
	
	vite: {
		build: {
			rollupOptions: {
			  output: {
				manualChunks: undefined
			  }
			}
		  },
		resolve: {
			alias: {
				$bootstrap: path.resolve('./node_modules/bootstrap/scss')
			}
		}
	}
},
server: {
	fs: {
	  // Allow serving files from one level up to the project root
	  allow: [
		  searchForWorkspaceRoot(process.cwd()),
		  '../',
		  '../..'
	  ]
	}
  }

}

export default config

@raphet
Copy link

raphet commented Apr 3, 2022

I am also impacted by this error with same two resolutions:

A) downgrading to "@sveltejs/kit": "1.0.0-next.199"
B) placing empty index.svelte files in those folders

The issue was definitely introduced by #2832 and is reproduced in conjunction with using adapter-static.
As others stated there is no issue with npm run dev.
But the build process failes during npm run build with a 404 error, in my case > 404 /blog (linked from /blog/my-first-article). That /blog folder has no index file but it also doesn't need to have one.
Worse yet: /blog is not even linked from within the article. So the error message is misleading.

@benmccann benmccann added help wanted PRs welcomed. The implementation details are unlikely to cause debate and removed help wanted labels Apr 4, 2022
@Rich-Harris
Copy link
Member

Both repros work correctly with the current version of SvelteKit, so whatever the bug was we can regard it as fixed — closing

@quintesse
Copy link

I have a brand new repo that shows this problem as well: https://github.com/quintesse/comix-sense
It's the SvelteKit demo app where the only changes that have been made are configuring it with the static adapter.
You can see the error in the GH Action log: https://github.com/quintesse/comix-sense/runs/6859572148
Am I doing something wrong?

@Eric-ASCE
Copy link

Eric-ASCE commented Nov 16, 2022

I had the same error and I found what happend, is simple when you run "npm run build" as static it start to compile the project and svelte verify all routes used as local routes, as you are using "/support/FAQ/..." in some href, sveltekit is trying to find this route but it is not defined in your project may be because a typo or you just wrote any route to fill the atribute when testing. If you run as "npm run dev" it will not show the error

@maximeoger
Copy link

maximeoger commented Mar 18, 2023

Hello, i know that this issue have been closed already, but i would like to share a similar problem i had with my project using static-adapter on @sveltejs/kit: ^1.11.0

When i build the project in my local computer, the files are generated correctly and the build works fine. But i get the same error on my github actions CI.

Here the link of the failing job:
https://github.com/maximeoger/personal_website/actions/runs/4437285939/jobs/7786777261

And my project repository:
https://github.com/maximeoger/personal_website/tree/dev

The problem is about a 404 error on the "/" path. And i can't have more ideas about how this could fail on CI...

Thanks in advance for any help.

@P00HB33R
Copy link

Adding the following in the head of my app.html fixed the error for me:
<base href="/" />

@faelisrex
Copy link

im having this problem too. svg files load in npm run dev but not during build. im using "@sveltejs/adapter-auto": "^3.0.0" and "@sveltejs/kit": "^2.0.0" ill likely not want to downgrade as far back as 1.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted PRs welcomed. The implementation details are unlikely to cause debate p3-edge-case SvelteKit cannot be used in an uncommon way pkg:adapter-static
Projects
None yet
Development

Successfully merging a pull request may close this issue.