Access to font at has been blocked by CORS policy. #32069
-
What version of Next.js are you using?12.0.4 What version of Node.js are you using?Vercel Current (sorry, didn't find) What browser are you using?Chrome What operating system are you using?Windows How are you deploying your application?Vercel Describe the BugHello! I have two fonts that don't work on my site. In the google chrome console I get an error like this:
This is the css code that drives the font.
Expected BehaviorTwo working fonts. To Reproduce |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 1 reply
-
Your repository is private. |
Beta Was this translation helpful? Give feedback.
-
@balazsorban44 |
Beta Was this translation helpful? Give feedback.
-
So what do you think? |
Beta Was this translation helpful? Give feedback.
-
@Maxet24 Remove relative imports to Working repo: https://github.com/mattcarlotta/crazy-suit-cases-fork Changes made: On that note, if you're trying to utilize assets across different domains, then this can be considered anti-pattern. Instead, you'll want to use a CDN. There are ways around it, like adding CORS to a Next project, but ideally this should be avoided. |
Beta Was this translation helpful? Give feedback.
-
I have tried accessing it from public by utilizing the base URL /. I am still having CORS error |
Beta Was this translation helpful? Give feedback.
-
Hi guys, I am having the same scenario, in which my fonts are in our design system, consume as a node module. Error: This webpack configuration in nextjs.config,js resolved the error for me:
|
Beta Was this translation helpful? Give feedback.
-
I am facing the same issue uploaded the build file to the S3 bucket all the CSS, JS and images worked fine but the font is getting this error import { Nunito } from "next/font/google"; //font config export const nunito = nunito_init.variable; |
Beta Was this translation helpful? Give feedback.
@Maxet24 Remove relative imports to
public
and instead request public assets via the base URL/
which utilizes public static file serving.Working repo: https://github.com/mattcarlotta/crazy-suit-cases-fork
Working demo: https://crazy-suit-cases-fork.vercel.app/
Changes made:
pages/_document.js (optional -> preload fonts to reduce FOUC)
pages/index.js (invalid nesting -> p cannot be a descendant of p)
styles/global.css (request assets from
public
by utilizing the base URL/
)On that note, if you're trying to utilize assets across different domains, then this can be considered anti-pattern. Instead, you'll want to use a CDN. There are ways around it, like adding CORS to a Next project, but…