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

Incorrect build path for prerendered endpoints when setting a basepath (kit.paths.base) #3620

Closed
yannp00 opened this issue Jan 29, 2022 · 2 comments
Labels
bug Something isn't working paths.base bugs relating to `config.kit.paths.base`
Milestone

Comments

@yannp00
Copy link

yannp00 commented Jan 29, 2022

Describe the bug

When setting a basepath with kit.paths.base, the prerenderer does not store the prerendered pages and endpoints in the same path, resulting in error when trying to access them.
If basepath is set to /mybasepath, pages will end up in the build/ folder, whereas endpoints will be in build/mybasepath/ folder.

Reproduction

Clone https://github.com/aryga/sveltekit-basepath.git (a minimal project created with create-svelte)

npm install
npm run build

svelte.config.js contains:


/** @type {import('@sveltejs/kit').Config} */
const config = {
	kit: {
		adapter: adapter(),
		paths: { base: '/myapp' },
		target: '#svelte'
	}
};

export default config;

Site structure:

routes
--index.svelte
--mypage
----index.svelte
----mypage.json.js

As a result, the prerenderer generates files like this:

--_app
--index.html
--mypage
----index.html
--myapp
----mypage
------mypage.json

The endpoint and page that are in the same route "mypage" are not prerendered to the same folder.

When you deploy the build folder onto a flat-file server in a folder "myapp", then navigate to the index (is /myapp), then to the myapp/mypage page, it will open with error - it looks for /myapp/mypage/mypage.json when that file is in /myapp/myapp/mypage/mypage.json

Note that dev or preview will work, it somehow finds its way to the file in these modes.

Could not load text from endpoint
Error: Could not load text from endpoint
    at H (https://[mysite.com]/myapp/_app/pages/mypage/index.svelte-2a470229.js:1:747)
    at async qe._load_node (https://[mysite.com]/myapp/_app/start-e76574a6.js:1:19806)
    at async qe._load (https://[mysite.com]/myapp/_app/start-e76574a6.js:1:20635)
    at async qe._get_navigation_result (https://[mysite.com]/myapp/_app/start-e76574a6.js:1:18038)
    at async qe.update (https://[mysite.com]/myapp/_app/start-e76574a6.js:1:16039)
    at async qe.handle_navigation (https://[mysite.com]/myapp/_app/start-e76574a6.js:1:15956)
    at async Ce._navigate (https://[mysite.com]/myapp/_app/start-e76574a6.js:1:12353)

Moving build/myapp/mypage/mypage.json to build/mypage/mypage.json fixes the problem.

Logs

No response

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
    Memory: 4.93 GB / 15.92 GB
  Binaries:
    Node: 14.17.6 - C:\Program Files\nodejs\node.EXE
    npm: 7.23.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 97.0.4692.99
    Edge: Spartan (44.22000.120.0), Chromium (97.0.1072.76)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.17
    @sveltejs/adapter-static: ^1.0.0-next.26 => 1.0.0-next.26
    @sveltejs/kit: next => 1.0.0-next.250
    svelte: ^3.44.0 => 3.46.3

Severity

serious, but I can work around it

Additional Information

Workaround: move the files from build/myapp to build/ when deploying

FYI, I could not get it to work at all with adapter-netlify, myapp/mypage would not load at all but I did not try to check if it was related.

bundabrg added a commit to bundabrg/kit that referenced this issue Feb 24, 2022
* Add `base` to builder
* Prepend `builder.base` when copying Client, Static and Prerendered assets in adapter-node

Fixes sveltejs#3726
Related sveltejs#3620
@lkostrowski
Copy link

Do you know if any previous version works, so we can rollback? Indeed this is a serious problem - is it a regression?

@Rich-Harris Rich-Harris added bug Something isn't working paths.base bugs relating to `config.kit.paths.base` labels May 16, 2022
@Rich-Harris Rich-Harris added this to the 1.0 milestone May 16, 2022
@Rich-Harris Rich-Harris modified the milestones: 1.0, post-1.0 Aug 27, 2022
@Rich-Harris
Copy link
Member

This is fixed in newer versions — closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working paths.base bugs relating to `config.kit.paths.base`
Projects
None yet
Development

No branches or pull requests

3 participants