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

Getting 404 for script.js #1

Closed
bogy0 opened this issue Oct 25, 2022 · 57 comments
Closed

Getting 404 for script.js #1

bogy0 opened this issue Oct 25, 2022 · 57 comments
Labels
bug Something isn't working

Comments

@bogy0
Copy link

bogy0 commented Oct 25, 2022

First of all, great work with the updates. Watching the conference was really inspiring.
Of course, my first thing to do was to update one of my Next.js projects and try the new goodies.

At one point I decided to try out this new Analytics feature called Audiences, but after adding it to the project I am getting these errors in the console.
Screenshot 2022-10-25 at 23 46 55

After some quick search in the vercel org I came across this repository where I found a reference for this va/script.js file.
Screenshot 2022-10-25 at 23 50 22

Overall, the audiences feature is working, I am getting visitor data in the newly enabled dashboard page; the issue only is that the browser logging this error.

If you need further details, example codes, let me know, but what i did was basically follow your guide:

  • install @vercel/analytics
  • import and place the Analytics react component into the _app.jsx file, like this:
import { Analytics } from '@vercel/analytics/react';

import '../styles/globals.css'

const MyApp = ({Component, pageProps }) => {
  return (
      <>
        <Component {...pageProps} />
        <Analytics />
      </>
  );
}

export default MyApp
@bogy0 bogy0 changed the title Browser error logged in the console after adding Audiences to a Next.js app Browser error logged in the console after adding @vercel/analytics to a Next.js app Oct 25, 2022
@frontsideair
Copy link

I'm also having a similar problem. I don't get any analytics data on my dashboard though.

I added this to my Gatsby project by adding inject to gatsby-browser.js, which does its job and adds the script to the <head>. But the va/script.js gives a 404, which makes sense because there's no such file anywhere. Is Vercel supposed to intercept and serve this file?

I also have rewrites defined in my project so maybe this is overriding the hypothesized intercept. This may be an edge case.

@NuroDev
Copy link

NuroDev commented Oct 26, 2022

But the va/script.js gives a 404, which makes sense because there's no such file anywhere. Is Vercel supposed to intercept and serve this file?

Yeah same here. Have another site that has this package working & manually added the /va/script.js to my public/ directory but then got another error from failing to post to /va/view.

Does seem like it's usually expected that Vercel will add / intercept any requests to /va/... endpoint(s) but it isn't for some reason?

@alex-grover
Copy link

alex-grover commented Oct 26, 2022

Seeing a 404 as well with an Astro project, using both the plain HTML approach as well as using inject().

@max
Copy link

max commented Oct 26, 2022

Possibly not the reason y'all are seeing the error but I was also getting a 404 for the injected script when deploying @vercel/analytics. Turns out you first have to enable the feature in the dashboard and then deploy the library (a re-deploy fixed it for me).

@bogy0
Copy link
Author

bogy0 commented Oct 26, 2022

Unfortunately, re-deploying my project is not solved the error log in my case.

@chriswdmr
Copy link
Member

chriswdmr commented Oct 26, 2022

As @max correctly pointed out, the mentioned path /va/script.js will become available on your next deployment after you enabled the feature.

If you added the package before you enabled the feature, you can trigger a redeployment which has the same effect.

@bogy0 It seems like the error you're seeing is related to your browser as you already get data. Have you tried disabling all extensions/ad-blockers?

@tomegger
Copy link

Same problem here. I´ve already tried all steps (re-deploying, enabling/disabling, etc.) but still have the same error as @bogy0.

@chriswdmr
Copy link
Member

Would you mind creating a minimal reproduction?

Ideally a small repo that gets deployed to Vercel so we can have a closer look!

@bogy0
Copy link
Author

bogy0 commented Oct 26, 2022

will do later today

@tomegger
Copy link

I´ve also a simple app if you want to take a look

@frontsideair
Copy link

I also tried redeploying but didn't work in my case. It's not minimal but my blog, for which I want to use the analytics, is open-source.

@chriswdmr
Copy link
Member

I also tried redeploying but didn't work in my case. It's not minimal but my blog, for which I want to use the analytics, is open-source.

Thanks for providing an example!

It seems like that your custom 404 page is catching all routes – including the /va/script.js URL.
You have to instrument Gatsby in a way that it ignores this URL.

@frontsideair
Copy link

Thanks, I added the redirect manually to bypass Gatsby with the this config, which is transformed with gatsby-plugin-zeit-now plugin. This fixed the 404 issue and requests are actually sent and response is received, but my dashboard doesn't load any data.

@chriswdmr
Copy link
Member

@frontsideair the script is available behind your own domain and not via vercel.com.
Please change vercel.com to your own domain.

@frontsideair
Copy link

I understand and removed the redirect to vercel.com, I haven't found a good workaround so I'm giving up on this for now. Waiting for an official solution.

@mehulmpt
Copy link

Same for us. With rewrites enabled the @vercel/analytics script throws 404.

@GizmoRay
Copy link

+1 - facing the same issue. Some guidance on how best to handle both a 404 page + allowing the analytics package to come through would be great.

@pyronaur
Copy link

I created a static blank /va/script.js on my Astro site in hopes that would get replaced, but looks like that didn't do anything either.

@vojto
Copy link

vojto commented Oct 27, 2022

Same issue with SvelteKit.

@schnubor
Copy link

schnubor commented Oct 27, 2022

Having the same problem (script 404) on a Next 13 app (still using /pages) with a custom 404 page. disabled & enabled the feature in the vercel UI again and redeployed, still 404ing. Also not seeing any data in the Audience dashboard which I think is just a side effect. It says "Vercel Analytics is set up, but detected a non-production environment." on my local though, so it's at least trying to do something.

@diffTed
Copy link

diffTed commented Oct 27, 2022

Same here (Next 13)

@tobiaslins tobiaslins added the bug Something isn't working label Oct 27, 2022
@tobiaslins
Copy link
Collaborator

We're actively working on a solution for this issue. We'll keep you posted!

@sgarcia22
Copy link

Same problem, I get a Uncaught SyntaxError: Unexpected token '<' (at script.js:1:1) and cannot access any analytics.

I'm using Vue v2, and tried injecting it with the inject() call in both the app.js mounted() callback, and in main.js when creating the Vue app.

Also tried using it in the HTML <script async src="/va/script.js"></script>.

In my routes I have this however, not sure if that is causing a problem like the comments above or how I would go about fixing that.

  {
    path: "/:catchAll(.*)",
    name: "NotFound",
    redirect: "/",
    meta: {title: "😔 - 404"},
  },

@remisture
Copy link

We're actively working on a solution for this issue. We'll keep you posted!

Any updates?

@aprendendofelipe
Copy link

There seems to be an incompatibility with the i18n configuration in next.config.js.

@JoshLittlewood
Copy link

Removing i18n from my next.config.js did resolve the issue for me.

@frontsideair
Copy link

Works for me as well, thanks! As a docs suggestion, I added the inject script to gatsby-node.js for Gatsby, as it seemed like the correct place for it.

@paulmwatson
Copy link

Thanks @dglsparsons, just did a re-deploy there (leaving analytics enabled) and same error.

@darasus
Copy link

darasus commented Nov 2, 2022

Same, redeployed multiple times while analytics enabled and still seeing 404

@dglsparsons
Copy link
Collaborator

Okay, it seems like we still have some issues relating to i18n interfering with analytics. We're working on a fix for sites using i18n now. I believe sites without i18n should work fine though.

@vacodoceo
Copy link

@tobiaslins still having the same error with SvelteKit

@tobiaslins
Copy link
Collaborator

@vacodoceo can you please share the last deployment url with us to take a closer look?

@Robin-w151
Copy link

I can confirm that it is now working for my SvelteKit app after I did a redeployment and leaving audiences enabled.

@dglsparsons
Copy link
Collaborator

Hi, further update here: we've shipped a change that should resolve any issues with i18n interference. You'll need to redeploy (again) to see the changes, but 🤞 this resolves any remaining issues! Let me know if it doesn't work :)

@vacodoceo
Copy link

@tobiaslins I just checked again and it's working. I enabled audiences, redeployed, and it started working. It's strange because I redeployed a couple of times an hour ago and it didn't work, and I don't think enabling audiences was what fixed it.

Anyway, thanks for the support!

@tobiaslins
Copy link
Collaborator

@vacodoceo we just rolled out a fix for i18n, it takes a while until it's available for everyone!
thanks for confirming 🤗

@tjkohli
Copy link

tjkohli commented Nov 2, 2022

It works with SvelteKit after redeploying! Thank you so much. 🙏🏼

@tomegger
Copy link

tomegger commented Nov 2, 2022

It works now! 🙌

@paulmwatson
Copy link

Excellent, it works now, thanks for the work

@mehulmpt
Copy link

mehulmpt commented Nov 2, 2022

Works for us too 🙌

@schnubor
Copy link

schnubor commented Nov 2, 2022

Works, thanks! :)

@aprendendofelipe
Copy link

Now it's working with i18n. Thanks!

@Dogtiti
Copy link

Dogtiti commented Apr 30, 2023

same issue

@tobiaslins
Copy link
Collaborator

@FlatMapIO @Dogtiti can you please send me a deployment URL so I can take a look for you? Happy to dig deep!

@Dogtiti
Copy link

Dogtiti commented May 2, 2023

@tobiaslins
Copy link
Collaborator

@Dogtiti It seems like you've already collected data once with that domain but currently Web Analytics for that project is disabled. Head over to the Analytics tab for this project, enable it & redeploy to start collecting data again!

@Dogtiti
Copy link

Dogtiti commented May 2, 2023 via email

@reevosolutions
Copy link

I think this happens when you integrate the analytics on your project without activating the analytics on Vercel

@valdemardev01
Copy link

valdemardev01 commented Oct 26, 2023

Found out that mby if you use adblock, that will stop the script.js from running.

@rkreicbergs-sorsera
Copy link

rkreicbergs-sorsera commented Nov 15, 2023

We also get 404 errors in Datadog, but not sure it's the same issue.

  • We've enabled Analytics for our app and we actually see data in dashboard
  • we use the NPM package in our _app.tsx:
 import { Analytics } from "@vercel/analytics/react"; 
 [....]
<Analytics />
  • in DataDog we an error about 404 from https://vitals.vercel-insights.com/v1/view?dsn=vxVf....
    If I understand corretly, the plugin calls /_vercel/insights/view which gets the error and the logs it

  • as noted, we do see data in the dashbaord and this issue is intermittent, but seems to happen at least once in 2 days and we've done a bunch of new deployments since enabling it - the problem persists

  • last error today was for sorsera-bzouxhxkx-sorsera.vercel.app

Can any of this be explained by ad blockers? IIUC, that could not explain it - it would simple not call /_vercel/insights/view at all and thus we'd not get any errors, no?

Can this be explained by a crawler or smth accessing /_vercel/insights/view directly? if I open it manually, just got the same type of error in DataDog. Can I enable some input validation for that page or something? If nothing else, we'll just ignore all those logs completely, which doesn't seem like the right approach.

@oucar
Copy link

oucar commented Apr 14, 2024

I got the exact same error, in my environment my ad blocker was causing the issue. Disabling it solved the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests