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

Can't import fonts outside the root #1531

Closed
3 tasks done
cawa-93 opened this issue Jan 14, 2021 · 3 comments · Fixed by #1537
Closed
3 tasks done

Can't import fonts outside the root #1531

cawa-93 opened this issue Jan 14, 2021 · 3 comments · Fixed by #1537

Comments

@cawa-93
Copy link
Contributor

cawa-93 commented Jan 14, 2021

⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.

  • Read the docs.
  • Use Vite >=2.0. (1.x is no longer supported)
  • If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.

Describe the bug

If the root is not at the same level as the node_modules, then when you try to import a fonts from node_modules, the fonts are not loaded.

The style file itself is successfully imported. However, fonts are requested at:

http://localhost:3000/@fs/Users/username/project/node_modules/element3/lib/theme-chalk/fonts/element-icons.woff

always returns with 404 error.

Reproduction

  • Clone repo
  • npm install
  • npm run dev

System Info

  • vite version: 2.0.0-beta.27
  • Operating System:Windows
  • Node version:14.15.3
  • Package manager (npm/yarn/pnpm) and version: npm@6.14.10
@yyx990803
Copy link
Member

Hmm, the repro works for me on macOS, likely a windows path related issue.

@develar
Copy link

develar commented Mar 2, 2021

Please reopen. It is broken by 1342108 (cc @CHOYSEN ). I think that eslint rules should be fixed or smart IDE like IntelliJ IDEA should be used to catch such regression.
Screenshot 2021-03-02 at 18 16 20

Fix is very trivial:

Index: packages/vite/src/node/server/middlewares/static.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/packages/vite/src/node/server/middlewares/static.ts b/packages/vite/src/node/server/middlewares/static.ts
--- a/packages/vite/src/node/server/middlewares/static.ts	(revision 67e56e48dac7875a2916845614bfb970722744a0)
+++ b/packages/vite/src/node/server/middlewares/static.ts	(date 1614705374177)
@@ -71,6 +71,7 @@
     if (url.startsWith(FS_PREFIX)) {
       url = url.slice(FS_PREFIX.length)
       if (isWin) url = url.replace(/^[A-Z]:/i, '')
+      req.url = url
       serveFromRoot(req, res, next)
     } else {
       next()

develar added a commit to develar/vite that referenced this issue Mar 2, 2021
@cawa-93
Copy link
Contributor Author

cawa-93 commented Mar 2, 2021

@develar See #2309

@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

Successfully merging a pull request may close this issue.

3 participants