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

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

Closed
vfilatov opened this issue May 11, 2021 · 7 comments
Labels

Comments

@vfilatov
Copy link

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

@Conduitry
Copy link
Member

Conduitry commented May 11, 2021

There are a couple of issues opened directly on the Vite repo currently that all seem to be about this. There's one PR vitejs/vite#3350 open for it that I have not looked at. In the meantime, we're considering pinning Kit to Vite 2.2.

edit: It sounds like that's just for fixing an issue on Windows. There are other cross-platform issues present that have issues on Vite's tracker, which are probably all different facets of the same thing.

@JustinVoitel
Copy link

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.

@dominikg
Copy link
Member

that check has been disabled by default in vite 2.3.1, so if you are seeing this issue, please update

@wiesson
Copy link
Contributor

wiesson commented May 12, 2021

that check has been disabled by default in vite 2.3.1, so if you are seeing this issue, please update

Btw, it looks like that 1.0.0-next.105 does not include the pinning to Vite version 2.2.4 - could you release that as well? (Or bump it directly to 2.3.1) - In my case, I always get 2.3.0 :(

@dominikg
Copy link
Member

#1429

@wiesson
Copy link
Contributor

wiesson commented May 12, 2021

Hmm, maybe something is wrong with my setup, but I still see this error (in development). I also tried to add

fsServe: {
  strict: false,
},

@ignatiusmb
Copy link
Member

I can't reproduce with the latest version, no errors are being logged in the console anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants