-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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
^11.1.2 - Using cdn for assets results in CORS error only for some css files not all #34225
Comments
I'm seeing this also (with 11.1.3). Any luck? |
Could any of you try with |
I haven't tried canary yet, but I did upgrade to Specifically it seems to be successfully fetching the css resources when they are included in the html (from the initial server side render, this is CORS exempt) but then client side navigations via router trigger a javascript What's odd to me is that it seems like the S3 typically omits the CORS response headers if the
This confirms that S3/CDN are suitably configured, and suggests that somehow |
It's not my favorite solution, but our CDN is quite configurable so I ended up custom scripting a solution to workaround this. I just modified the responses to ensure that the CORs headers are included even in the absence of request I would still love to understand the root cause of the missing header, and see a fix if it's a next bug. |
@ijjk can you please look at this. solutions tried: Our CDN is fine, all other files are downloaded and only a few css files where transition is from ssr to static html pages is creating an issue. Also we see no issue with js files, they are being downloaded. |
@jschlechtehomer @ijjk any findings? |
@sidreddyinsider nope; we just moved on with the CDN altering the headers to bridge the gap. |
I believe this is not next js issue. It is CDN configuration. Note: Using * for simplicity.
if you are using the AWS cloudfront you can go to to Good luck |
We are having the same issue but with multiple 3rd party vendors. It's kind of difficult to reach out to all the vendors and tell them to fix their CDN settings. This should be something we can control in the Next config somehow. |
This may be a separate bug, but at least related: I've encountered the same CORS issue as described above - next app is hosted on This looks to be here:
The behavior I then see is an infinite refresh of the current page. I'm guessing this is happening a few lines later ( next.js/packages/next/src/shared/lib/router/router.ts Lines 1868 to 1880 in cc77579
It's additionally perplexing because I see this which supposedly should prevent a navigation to the same URL: next.js/packages/next/src/shared/lib/router/router.ts Lines 639 to 645 in cc77579
This all started with the introduction of a middleware. I'm not sure if next thinks middleware should run on this asset request, even though it is from a different (sub-)domain. |
It seems like a bug. Any solution? |
|
Hi There, We upgraded from Next 12 to Next 14, and started experiencing the same problem in our staging environment, so we have not released to prod yet. We did not change our CDN configuration and it was working with its current configuration for several months and Next 12. From the symptoms I have investigated when some _next/.js files fails due to CORS, those particular requests are missing the "Origin" request header which when absent makes the CDN config to not sent Access-Control-Allow-Origin in response header. I have read all the above comments and my issue is exactly similar with some assets not loading from CDN due to CORS. I think there is bug with Next or something new config we don't know. But if I roll back to our old version of Next, the problem goes away. |
This issue seems to have been fixed in some latest version: next.js/packages/next/src/export/index.ts Line 486 in 08e5424
|
@ild0tt0re any news on your PR? Is there a way to get around this issue without your fix? We are also having this issue... |
We are on 14.0.3 and still having this issue. |
No, please upvote it here #58200 In the meantime you can use patch subcommand of your package manager like |
@ild0tt0re apart from upvoting is there anything else we can do to gain some momentum on your PR? It would be great to get it fixed... |
Got this problem recently. I added the:
I'm using |
Nevermind. It's my cdn service issue: I need to add |
Run
next info
(available from version 12.0.8 and up)"next": "^11.1.2",
What version of Next.js are you using?
"next": "^11.1.2",
What version of Node.js are you using?
15.0.1
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
next start in aws
Describe the Bug
I am deploying my nextjs application in a single ec2 instance in aws.
I deploy the next assets _next/static in a s3 bucket, and they are served via cloudfront
in next.config.js i put correctly assetPrefix to my cdn:
NOTE: I replaced client domain with domain.com for privacy reason, everything else is documented with real data from the bug scenario.
The above config works fine, on deployment app tries to get files from cdn and works for 95 % of js/css.
Issue is that I get cors error for only some CSS which is crazy!
Most of page deployed works fine can load js/css in my cdn _next/static folder, but some css fail and this causes particular routes not to load!!! and user face silent errors
screenshoot of network tab
shows that some css are loading some no. .js files load fine from the cdn. My domain is allowed in s3 bucket cors policies and is getting files correctly most of them I mean, as some css don't load.
Error in console is
I notice that for working css fetches, next sends cors headers correctly. I copied one chrome network request as curl and post below, that is working fine.
other times I see the cors error in network tab and this requst type ( no cors headers at all added by next load initiator somewhere at
main-70dd238….js:1
)Below request in screenshoot resulted in CORS error that I posted above
Expected Behavior
NextJS should be consistent, if it manages to load all js files and 95% of css over CDN , while sending same request headers I expect everything to work fine load all route assets 100% correctly and avoid silent errors like this.
To Reproduce
assetPrefix
in next.config.js to some cdn url that is using as source a s3 bucketyarn build && yarn start the next app in a domain that is subdomain of the cdn domain.
S3 bucket allows the website domain as CORS origin
What I tried already
next.config.js
I addedcrossOrigin: 'anonymous',
after a lot of online reasearch. Then build deployed and started, unfortunately did not help. Actually cors was broken totally after this change no asset could be loadedThe text was updated successfully, but these errors were encountered: