question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[vite] Internal server error: The request url "/api" is outside of vite dev server root

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
JustinVoitelcommented, May 11, 2021

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.

1reaction
dominikgcommented, May 12, 2021
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found