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

unexpected behavior when run npm run dev after set config.paths.base in svelte.config.js #2465

Closed
xcao38 opened this issue Sep 20, 2021 · 19 comments
Labels
bug Something isn't working
Milestone

Comments

@xcao38
Copy link

xcao38 commented Sep 20, 2021

Describe the bug

After set config as following in svelte.config.js:

/** @type {import('@sveltejs/kit').Config} */
import node from '@sveltejs/adapter-node';

const config = {
	kit: {
		// hydrate the <div id="svelte"> element in src/app.html
		target: '#svelte',
		adapter: node({
			// default options are shown
			out: 'build',
			precompress: false,
			env: {
				host: 'HOST',
				port: 'PORT'
			}
		}),
		paths: {
			assets: '',
			base: '/testdir'
		}
	}
};

export default config;
  1. Run npm run dev:
    In http://localhost:3000/testdir, I got the following:
Error: Not found: 
    at resolve (file:///Users/xiaofengcao/projects/svelte/my-app/node_modules/@sveltejs/kit/dist/ssr.js:1728:13)
    at async Object.handle (//Users/xiaofengcao/projects/svelte/my-app/src/hooks:13:19)
    at async respond (file:///Users/xiaofengcao/projects/svelte/my-app/node_modules/@sveltejs/kit/dist/ssr.js:1675:10)
    at async svelteKitMiddleware (file:///Users/xiaofengcao/projects/svelte/my-app/node_modules/@sveltejs/kit/dist/chunks/index.js:4531:22)
  1. Run npm run build & npm run preview:
  • app was successfully built
  • after npm run preview, a lot of js and css file did not picked up, please see the errors in the web console.
    image

Reproduction

Step 1: start a sveltekit app: https://kit.svelte.dev/

npm init svelte@next my-app
cd my-app
npm install
npm run dev -- --open

Step 2: change svelte.config.js to following:

/** @type {import('@sveltejs/kit').Config} */
import node from '@sveltejs/adapter-node';

const config = {
	kit: {
		// hydrate the <div id="svelte"> element in src/app.html
		target: '#svelte',
		adapter: node({
			// default options are shown
			out: 'build',
			precompress: false,
			env: {
				host: 'HOST',
				port: 'PORT'
			}
		}),
		paths: {
			assets: '',
			base: '/testdir'
		}
	}
};

export default config;

Step 3: install @sveltejs/adapter-node

npm i -D @sveltejs/adapter-node@next

Then run npm run dev or npm run build and npm run preview.

Logs

No response

System Info

npx: installed 1 in 1.189s

  System:
    OS: macOS 11.5.2
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 11.10 GB / 32.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 14.17.3 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.13 - /usr/local/bin/npm
  Browsers:
    Chrome: 93.0.4577.82
    Firefox: 90.0.2
    Safari: 14.1.2
  npmPackages:
    @sveltejs/adapter-node: ^1.0.0-next.49 => 1.0.0-next.49 
    @sveltejs/kit: next => 1.0.0-next.170 
    svelte: ^3.34.0 => 3.42.6 

Severity

blocking all usage of SvelteKit

Additional Information

We are trying to release a sveltekit app under a sub url. This is seriously blocking our deployment.

@benmccann
Copy link
Member

We just released a change affecting kit.paths.base (changelog. CC @Karlinator). Do you get the same error with version 1.0.0-next.169?

@Karlinator
Copy link
Contributor

This is only an issue in preview, right? I think this is just #2409 showing up?

Does it run correctly with npm run dev and when using the node adapter (node build after npm run build)? If it does, then this should be fixed by #2409

@xcao38
Copy link
Author

xcao38 commented Sep 20, 2021

This is only an issue in preview, right? I think this is just #2409 showing up?

Does it run correctly with npm run dev and when using the node adapter (node build after npm run build)? If it does, then this should be fixed by #2409

@benmccann @Karlinator thanks. Do you mind show me the command to upgrade to the latest version?

@xcao38 xcao38 closed this as completed Sep 20, 2021
@xcao38 xcao38 reopened this Sep 20, 2021
@Karlinator
Copy link
Contributor

@xcao38 #2409 isn't merged yet, so you won't get it even with upgrading. It'll probably be live soon-ish though. If your package.json has explicit version names (say, 1.0.0-next.169) you can just change that and run npm i. Also npm i -D @sveltejs/kit@1.0.0-next.170 will do the trick. If you have the version just specified as next then a simple npm update (or npm update @sveltejs/kit I think) will update.

@benmccann
Copy link
Member

This is only an issue in preview, right?

Not according to the issue report which says its an issue in dev and preview:

Then run npm run dev or npm run build and npm run preview.

@Karlinator
Copy link
Contributor

Ugh, my eyes betray me.

There might be a similar issue in the dev server, I haven't looked. I'm not as familiar with Vite and all that, but that would be my guess.

There is this line:

if (!parsed.pathname.startsWith(config.kit.paths.base)) return not_found(res);

Maybe assets are rejected at that point?

@Karlinator
Copy link
Contributor

@xcao38 do you have the full path of the files the browser is requesting? Is it requesting all assets in the correct locations (/testdir/_app/whatever) in both dev and preview (and are the paths the same in dev and preview)?

If those paths are all correct then I think we have one bug in preview (already known) and a separate but similar bug in dev (manifests the same, but caused differently since dev and preview servers are quite different internally, what with Vite etc).

@xcao38
Copy link
Author

xcao38 commented Sep 20, 2021

@xcao38 do you have the full path of the files the browser is requesting? Is it requesting all assets in the correct locations (/testdir/_app/whatever) in both dev and preview (and are the paths the same in dev and preview)?

If those paths are all correct then I think we have one bug in preview (already known) and a separate but similar bug in dev (manifests the same, but caused differently since dev and preview servers are quite different internally, what with Vite etc).

I could show you my file structure. Not sure where to find the files... Let me know if you need anything :)

image

@Karlinator
Copy link
Contributor

I meant the network log from the browser 😅 I want to see if the links and source urls embedded into the page are correct. In your devtools 'Network' tab you can click on the requests and just see if the Request URLs all have '/testdir/' in them. They should look like localhost:3000/testdir/_app/pages/whatever. If tehy look like localhost:3000/_app/pages/whatever (without 'testdir' in tehm) then we have a different problem.

@xcao38
Copy link
Author

xcao38 commented Sep 20, 2021

I meant the network log from the browser 😅 I want to see if the links and source urls embedded into the page are correct. In your devtools 'Network' tab you can click on the requests and just see if the Request URLs all have '/testdir/' in them. They should look like localhost:3000/testdir/_app/pages/whatever. If tehy look like localhost:3000/_app/pages/whatever (without 'testdir' in tehm) then we have a different problem.

Here you go:
image

@xcao38
Copy link
Author

xcao38 commented Sep 22, 2021

Hi @Karlinator thanks for the quick turnaround! Just curious, is there a timeline on releasing the new updates on paths.base?

@benmccann
Copy link
Member

benmccann commented Sep 22, 2021

The pretender change is in 170 and the preview mode change is in 171: https://github.com/sveltejs/kit/blob/master/packages/kit/CHANGELOG.md

@Karlinator
Copy link
Contributor

I don't think 170 or 171 actually fixes the dev mode issue here. 170 fixed an issue in pre-rendering, 171 fixed an issue in the preview server. I haven't had time to reproduce and go digging, but it looks like there's a separate issue in the dev server.

@xcao38
Copy link
Author

xcao38 commented Sep 22, 2021

@benmccann @Karlinator Thanks both for your time! FWIW, I upgraded my sveltekit to 171 with following:
npm add -D @sveltejs/kit@1.0.0-next.171.

Then I run npm run build and npm run preview, the problem with assets not found is gone. What I can see on my screen and console is as following:

Broswer:

image

Console:

image
image

Terminal:

(base) Xiaofengs-MacBook-Pro:my-app xiaofengcao$ npm run preview

> my-app@0.0.1 preview /Users/xiaofengcao/projects/svelte/my-app
> svelte-kit preview


  SvelteKit v1.0.0-next.171

  local:   http://localhost:3000
  network: not exposed

  Use --host to expose server to other devices on this network

My package.json

{
  "name": "my-app",
  "version": "0.0.1",
  "scripts": {
    "dev": "svelte-kit dev",
    "build": "svelte-kit build",
    "preview": "svelte-kit preview"
  },
  "devDependencies": {
    "@sveltejs/adapter-node": "^1.0.0-next.49",
    "@sveltejs/kit": "^1.0.0-next.171",
    "svelte": "^3.34.0"
  },
  "type": "module",
  "dependencies": {
    "@fontsource/fira-mono": "^4.5.0",
    "@lukeed/uuid": "^2.0.0",
    "cookie": "^0.4.1"
  }
}

@Karlinator
Copy link
Contributor

I believe you need the trailing slash, so localhost:3000/testdir/.

@xcao38
Copy link
Author

xcao38 commented Sep 22, 2021

I believe you need the trailing slash, so localhost:3000/testdir/.

Thank you! very helpful. Yeah it did the trick:)

@benmccann benmccann changed the title unexpected behavior when run npm run dev and npm run build after set config.paths.base in svelte.config.js unexpected behavior when run npm run dev after set config.paths.base in svelte.config.js Sep 22, 2021
@maiertech
Copy link

This is still an issue in 177. Once you revert to Vite for previewing, will this fix the issue when there is no trailing /?

@benmccann
Copy link
Member

I don't think we'll use Vite for preview mode actually. What they do for their preview mode is too different (e.g. it doesn't do SSR at all)

@benmccann benmccann added this to the 1.0 milestone Jan 18, 2022
@benmccann benmccann added the bug Something isn't working label Jan 18, 2022
@benmccann
Copy link
Member

Closing this as a duplicate of #2958

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

No branches or pull requests

4 participants