Getting 404 on get request for generated file .svelte-kit/generated/client/app.js when running local development server

huangapple go评论69阅读模式
英文:

Getting 404 on get request for generated file .svelte-kit/generated/client/app.js when running local development server

问题

我正在学习Svelte-kit,并且正在处理一个现有的项目。然而,当我尝试以开发模式运行项目时,我遇到了一个问题。

问题出现在我尝试使用vite dev在本地运行我的项目时。当我尝试访问一个站点时,会发出一个对文件.svelte-kit/generated/client/app.js的GET请求,结果是404未找到错误。站点会渲染,但似乎被冻结了。

问题似乎是我的应用程序试图在我的机器上使用绝对路径来定位此文件,而不是正确的路径,即localhost:5173/.svelte-kit/generated/client/app.js。如果我尝试通过这个URL直接访问文件,它会正常工作。

然而,当进行GET请求时,它会使用路径:localhost:5173/@fs/home/<myuser>/<myprojectfolder>/.svelte-kit/generated/client/app.js,导致以下错误:

Error: Not found: /@fs/home/<myuser>/<myprojectfolder>/.svelte-kit/generated/client/app.js
    at resolve (/home/<myuser>/<myprojectfolder>/node_modules/@sveltejs/kit/src/runtime/server/respond.js:473:13)
    at resolve (/home/<myuser>/<myprojectfolder>/node_modules/@sveltejs/kit/src/runtime/server/respond.js:282:5)
    at #options.hooks.handle (/home/<myuser>/<myprojectfolder>/node_modules/@sveltejs/kit/src/runtime/server/index.js:56:56)
    at Module.respond (/home/<myuser>/<myprojectfolder>/node_modules/@sveltejs/kit/src/runtime/server/respond.js:279:40)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

然而,当我构建应用程序并使用vite preview运行时,它完全正常。

这是我的svelte.config.js:

import { vitePreprocess } from '@sveltejs/kit/vite';
import adapter from '@sveltejs/adapter-node';

export default {
	preprocess: [vitePreprocess()],
	kit: {
		adapter: adapter(),
		csrf: {
			checkOrigin: false,
		}
	}
};

我的vite.config.js如下:

import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';

export default defineConfig({
	plugins: [sveltekit()]
});

我的package.json中的依赖项:

"devDependencies": {
    "@sveltejs/adapter-auto": "^2.0.0",
    "@sveltejs/kit": "^1.5.0",
    "svelte": "^3.54.0",
    "vite": "^4.0.0"
},
"type": "module",
"dependencies": {
    "@sveltejs/adapter-node": "^1.2.3",
    "bootstrap": "^5.2.3",
    "chart.js": "^4.2.1",
    "chartjs-adapter-date-fns": "^3.0.0",
    "date-fns": "^2.29.3",
    "form-data": "^4.0.0",
    "formdata-node": "^5.0.0",
    "mongodb": "^5.1.0",
    "node-fetch": "^3.3.1",
    "svelte-chartjs": "^3.1.2"
}

我尝试过删除node_modules和生成的代码,然后重新安装它,但没有任何改变。

我会感激任何关于为什么会发生这种情况的建议。

英文:

I am learning Svelte-kit and I am working on an existing project. However, when I try to run the project in development mode, I encounter a problem.

The issue arises when I attempt to run my project locally with vite dev. When I try to access a site there is a GET request for the file .svelte-kit/generated/client/app.js that results in a 404 Not found error. The site renders, but seems to be frozen.

The issue seems to be that my application is trying to locate this file using an absolute path on my machine rather than the correct path, which is localhost:5173/.svelte-kit/generated/client/app.js. If I attempt to access the file directly via this URL, it works correctly.

However, when the GET request is made, it utilizes the path: localhost:5173/@fs/home/<myuser>/<myprojectfolder>/.svelte-kit/generated/client/app.js, which results in the following error:

Error: Not found: /@fs/home/<myuser>/<myprojectfolder>/.svelte-kit/generated/client/app.js
    at resolve (/home/<myuser>/<myprojectfolder>/node_modules/@sveltejs/kit/src/runtime/server/respond.js:473:13)
    at resolve (/home/<myuser>/<myprojectfolder>/node_modules/@sveltejs/kit/src/runtime/server/respond.js:282:5)
    at #options.hooks.handle (/home/<myuser>/<myprojectfolder>/node_modules/@sveltejs/kit/src/runtime/server/index.js:56:56)
    at Module.respond (/home/<myuser>/<myprojectfolder>/node_modules/@sveltejs/kit/src/runtime/server/respond.js:279:40)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

However, when I build the application and run it with vite preview, it works perfectly fine.

Here's my svelte.config.js:

import { vitePreprocess } from '@sveltejs/kit/vite';
import adapter from '@sveltejs/adapter-node';

export default {
	preprocess: [vitePreprocess()],
	kit: {
		adapter: adapter(),
		csrf: {
			checkOrigin: false,
		}
	}
};

My vite.config.js is as follows:

import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';

export default defineConfig({
	plugins: [sveltekit()]
});

My dependencies in package.json:

	"devDependencies": {
		"@sveltejs/adapter-auto": "^2.0.0",
		"@sveltejs/kit": "^1.5.0",
		"svelte": "^3.54.0",
		"vite": "^4.0.0"
	},
	"type": "module",
	"dependencies": {
		"@sveltejs/adapter-node": "^1.2.3",
		"bootstrap": "^5.2.3",
		"chart.js": "^4.2.1",
		"chartjs-adapter-date-fns": "^3.0.0",
		"date-fns": "^2.29.3",
		"form-data": "^4.0.0",
		"formdata-node": "^5.0.0",
		"mongodb": "^5.1.0",
		"node-fetch": "^3.3.1",
		"svelte-chartjs": "^3.1.2"
	}

I have tried deleting node_modules and generated code and reinstalled it, but it did not make a difference.

I would appreciate any suggestions on why this may be happening.

答案1

得分: 0

我最终发现问题与我的项目路径中的一个文件夹中有空格有关,克隆存储库后,这些空格被编码为%20my%20project%20with%20spaces)。在从文件夹名称中移除%20后,开发服务器又开始正常工作。

英文:

I eventually found that the issue was related to having spaces in one of the folders in my project path, which after cloning the repository were encoded to %20 (my%20project%20with%20spaces). After removing the %20 from the folder name the development server started to work again.

huangapple
  • 本文由 发表于 2023年7月10日 22:47:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76654894.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定