[vite] Internal server error: The request url "/api" is outside of vite dev server root
See original GitHub issueDescribe the bug
After updating to Vite v2.3.0 I receive the following error:
[vite] Internal server error: The request url "/api" is outside of vite dev server root "/tmp/bug". For security concerns, accessing files outside of workspace root is restricted since Vite v2.3.x. Refer to docs https://vitejs.dev/config/#server-fsserveroot for configurations and more details.
To Reproduce
mkdir /tmp/bug && cd /tmp/bug
npm init svelte@next # all defaults
npm install
mkdir src/routes/api
cat <<EOF > src/routes/api/index.js
export async function get () {
return {
body: "World"
}
}
EOF
cat <<EOF > src/routes/bug.svelte
<script>
import { onMount } from 'svelte';
let name;
onMount(async () => {
const resp = await fetch("/api");
name = await resp.text();
})
</script>
Hello, { name }
EOF
run server npm run dev
navigate browser to http://localhost:3000/bug
observe error on the console
For security concerns, accessing files outside of workspace root is restricted since Vite v2.3.x.
Refer to docs https://vitejs.dev/config/#server-fsserveroot for configurations and more details.
at ensureServingAccess (/tmp/bug/node_modules/vite/dist/node/chunks/dep-c9ea388d.js:57841:15)
at transformRequest (/tmp/bug/node_modules/vite/dist/node/chunks/dep-c9ea388d.js:57883:17)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async viteTransformMiddleware (/tmp/bug/node_modules/vite/dist/node/chunks/dep-c9ea388d.js:58069:32) (x4)
Expected behavior not having such error
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:7 (6 by maintainers)
Top Results From Across the Web
I keep getting [vite] Internal server error: The request url "/path ...
I keep getting [vite] Internal server error: The request url "/path" is outside of vite dev server root "/path". when using vitepress #297....
Read more >Server Options - Vite
Configure custom proxy rules for the dev server. Expects an object of { key: options } pairs. Any requests that request path starts...
Read more >Vite/Vue3 throws Internal server error (experimental syntax ...
Judging by the issue and pull request above, the issue we're seeing seems to be explicitly caused by using decorators before export default...
Read more >Asset Bundling (Vite) - The PHP Framework For Web Artisans
If your local development web server is serving your application via HTTPS, you may run into issues connecting to the Vite development server....
Read more >The request url “/api/bill/list“ is outside of vite dev server root ...
Internal server error : The request url “/api/bill/list“ is outside of vite dev server root 怎么解决 ... 目录一.SQL 简介:用于访问和处理数据库的 ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I tried several cases and renaming the endpoint from index.ts to index.json.ts and calling fetch(“/api.json”) solved the issue for me.
https://github.com/sveltejs/kit/pull/1429