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

Error: Failed to load url /sw.js. Does the file exist? #1427

Closed
luoluoluo opened this issue Jan 8, 2021 · 7 comments
Closed

Error: Failed to load url /sw.js. Does the file exist? #1427

luoluoluo opened this issue Jan 8, 2021 · 7 comments

Comments

@luoluoluo
Copy link

luoluoluo commented Jan 8, 2021

image

npm run dev 后提示:

5:43:23 PM [vite] Internal server error:
Error: Failed to load url /sw.js. Does the file exist?
at transformRequest (/home/l/workspace/my-vue-app/node_modules/vite/dist/node/chunks/dep-85227760.js:66195:15)
at async /home/l/workspace/my-vue-app/node_modules/vite/dist/node/chunks/dep-85227760.js:66292:32
[@vue/compiler-sfc] <script setup> is still an experimental proposal.
Follow its status at vuejs/rfcs#227.

[@vue/compiler-sfc] When using experimental features,
it is recommended to pin your vue dependencies to exact versions to avoid breakage.

package.json内容如下:
{
"name": "my-vue-app",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"dependencies": {
"vue": "^3.0.5"
},
"devDependencies": {
"@vitejs/plugin-vue": "^1.0.4",
"@vue/compiler-sfc": "^3.0.5",
"vite": "^2.0.0-beta.12"
}
}

node 版本: v14.15.1
~

@chriscalo
Copy link

was there a resolution to this? I was getting the same “Does the file exist?” error but for /service-worker.js

@yyx990803
Copy link
Member

service workers should be placed in /public

@dajpes
Copy link

dajpes commented Jan 9, 2021

Same here, I don't use nor import any sw.js file, but vite out of the blue display that error

@yyx990803
Copy link
Member

yyx990803 commented Jan 9, 2021

You probably loaded another app with service worker on the same localhost port before, and your browser is thinking it's the same app and attempting to request the service worker. You need to delete your service worker for that localhost port (from Chrome devtools' application tab). Or, use a different port so Chrome doesn't get confused.

@dajpes
Copy link

dajpes commented Jan 9, 2021

Thank you @yyx990803, that was the error.

@dominikg
Copy link
Contributor

starting with vite 2.3.0 orphaned service workers produce a much noisier error message

[vite] Internal server error: The request url "/service-worker.js" is outside of vite dev server root "/my-app". 
      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.

Maybe vite should not try to fallback to fs root for paths without a directory structure? ie /foo/bar/baz.js would be searched for in and out of vite project root, but /baz.js only inside vite root.

@Conduitry
Copy link

There's another non-service-worker-related repro in sveltejs/kit#1420 using SvelteKit. Vite balks when the browser runs fetch('/api'). I feel this should get its own issue though.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants