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

Error in adapter-static when using paths.base and import assets #6767

Closed
ota-meshi opened this issue Sep 13, 2022 · 0 comments · Fixed by #6769
Closed

Error in adapter-static when using paths.base and import assets #6767

ota-meshi opened this issue Sep 13, 2022 · 0 comments · Fixed by #6769

Comments

@ota-meshi
Copy link
Member

ota-meshi commented Sep 13, 2022

Describe the bug

If I set paths.base, import .png or .svg, set it to src of <img> tag, and build using @sveltejs/adapter-static, I will get a 404 error.

<script>
	import logo from './svelte-logo.svg';
</script>

<header>
	<div class="corner">
		<a href="https://kit.svelte.dev">
			<img src={logo} alt="SvelteKit" />
		</a>
	</div>
Error: 404 /_app/immutable/assets/svelte-logo-87df40b8.svg does not begin with `base`, which is configured in `paths.base` and can be imported from `$app/paths` (linked from /foo/about)
    at eval (file:///home/projects/sveltejs-kit-template-default-sdspxa/node_modules/@sveltejs/kit/src/core/prerender/prerender.js:65:11)
    at visit (file:///home/projects/sveltejs-kit-template-default-sdspxa/node_modules/@sveltejs/kit/src/core/prerender/prerender.js:231:4)
    at Object.eval [as fn] (file:///home/projects/sveltejs-kit-template-default-sdspxa/node_modules/@sveltejs/kit/src/core/prerender/prerender.js:221:22)
    at dequeue (file:///home/projects/sveltejs-kit-template-default-sdspxa/node_modules/@sveltejs/kit/src/core/prerender/queue.js:53:42)
    at eval (file:///home/projects/sveltejs-kit-template-default-sdspxa/node_modules/@sveltejs/kit/src/core/prerender/queue.js:62:7)

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-sdspxa?file=src/lib/header/Header.svelte

  • open link
  • run npm run build

Logs

~/projects/sveltejs-kit-template-default-sdspxa 9s
❯ npm run build
$ vite build
vite v3.1.0 building for production...
✓ 52 modules transformed.
vite v3.1.0 building SSR bundle for production...
✓ 65 modules transformed.
.svelte-kit/output/server/vite-manifest.json                    3.07 KiB
.svelte-kit/output/server/index.js                              65.91 KiB
.svelte-kit/output/server/entries/pages/_layout.svelte.js       4.06 KiB
.svelte-kit/output/server/entries/fallbacks/error.svelte.js     0.60 KiB
.svelte-kit/output/server/entries/pages/_page.svelte.js         7.10 KiB
.svelte-kit/output/server/entries/pages/_page.js                0.05 KiB
.svelte-kit/output/server/entries/pages/about/_page.svelte.js   1.25 KiB
.svelte-kit/output/server/entries/pages/about/_page.js          0.09 KiB
.svelte-kit/output/server/entries/pages/todos/_page.svelte.js   5.93 KiB
.svelte-kit/output/server/entries/pages/todos/_page.server.js   1.35 KiB
.svelte-kit/output/server/chunks/index.js                       4.15 KiB
.svelte-kit/output/server/chunks/index2.js                      0.97 KiB
.svelte-kit/output/server/chunks/index3.js                      1.29 KiB
.svelte-kit/output/server/chunks/stores.js                      1.00 KiB
.svelte-kit/output/server/chunks/hooks.server.js                0.28 KiB
Error: 404 /_app/immutable/assets/svelte-logo-87df40b8.svg does not begin with `base`, which is configured in `paths.base` and can be imported from `$app/paths` (linked from /foo/about)
    at eval (file:///home/projects/sveltejs-kit-template-default-sdspxa/node_modules/@sveltejs/kit/src/core/prerender/prerender.js:65:11)
    at visit (file:///home/projects/sveltejs-kit-template-default-sdspxa/node_modules/@sveltejs/kit/src/core/prerender/prerender.js:231:4)
    at Object.eval [as fn] (file:///home/projects/sveltejs-kit-template-default-sdspxa/node_modules/@sveltejs/kit/src/core/prerender/prerender.js:221:22)
    at dequeue (file:///home/projects/sveltejs-kit-template-default-sdspxa/node_modules/@sveltejs/kit/src/core/prerender/queue.js:53:42)
    at eval (file:///home/projects/sveltejs-kit-template-default-sdspxa/node_modules/@sveltejs/kit/src/core/prerender/queue.js:62:7)
[vite-plugin-svelte-kit] Prerendering failed with code 1
error during build:
Error: Prerendering failed with code 1
    at ChildProcess.eval (file:///home/projects/sveltejs-kit-template-default-sdspxa/node_modules/@sveltejs/kit/src/exports/vite/index.js:454:15)
    at EventEmitter.emit (https://sveltejs-kit-template-default-sdspxa.w.staticblitz.com/blitz.a493d9b6541a4dd5b019a965004167e4adff5f2b.js:6:155574)
    at ChildProcess._handle.onexit (https://sveltejs-kit-template-default-sdspxa.w.staticblitz.com/blitz.a493d9b6541a4dd5b019a965004167e4adff5f2b.js:6:956236)
    at https://sveltejs-kit-template-default-sdspxa.w.staticblitz.com/blitz.a493d9b6541a4dd5b019a965004167e4adff5f2b.js:15:382032
    at _0x15340f (https://sveltejs-kit-template-default-sdspxa.w.staticblitz.com/blitz.a493d9b6541a4dd5b019a965004167e4adff5f2b.js:15:144844)
    at https://sveltejs-kit-template-default-sdspxa.w.staticblitz.com/blitz.a493d9b6541a4dd5b019a965004167e4adff5f2b.js:15:144593

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.73 
    @sveltejs/adapter-static: * => 1.0.0-next.43 
    @sveltejs/kit: next => 1.0.0-next.481 
    svelte: ^3.46.0 => 3.50.1 
    vite: ^3.1.0 => 3.1.0

Severity

annoyance

Additional Information

This issue seems to be from 1.0.0-next.475.
Perhaps the #6621 PR change introduced a bug.

I think we probably need to fix packages/kit/src/exports/vite/build/utils.js.

Before:

export function assets_base(config) {
return config.paths.assets + '/' || config.paths.base + '/' || './';
}

After:

 export function assets_base(config) { 
 	return (config.paths.assets || config.paths.base || '.') + '/'; 
 } 
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.

1 participant