Error on Nuxt and vercel/analytics

Problem with installing vercel analytics on nuxt project

npm i @vercel/analytics
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! @vercel/analytics@“" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @sveltejs/kit@2.9.0
npm ERR! node_modules/@sveltejs/kit
npm ERR! peerOptional @sveltejs/kit@“^1 || ^2” from @vercel/analytics@1.4.1
npm ERR! node_modules/@vercel/analytics
npm ERR! @vercel/analytics@"
” from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

npm i @vercel/analytics

“nuxt”: “^3.4.3”

Hi, @borisdmv!

Could you try the following?

  1. First, try installing the package with this command:
npm install @vercel/analytics --legacy-peer-deps
  1. Then, in your nuxt.config.ts, add the analytics module:
export default defineNuxtConfig({
  modules: ['@vercel/analytics'],
  // You can add optional configuration here if needed
})

If you run into any issues with this method, don’t worry! There’s an alternative approach:

export default defineNuxtConfig({
  app: {
    head: {
      script: [
        {
          src: '/_vercel/insights/script.js',
          defer: true
        }
      ]
    }
  }
})

This method injects the Vercel Analytics script directly into your app’s head.

Once you’ve set this up and deployed your Nuxt project to Vercel, you’ll be able to see your analytics data in your Vercel dashboard.

Let us know how you get on :smile:

1 Like

Thanks will test if all good will close that as Solution!

Sadly I get on build that now

[error] Cannot convert object to primitive value

npm error code 1

npm error path /vercel/path0

npm error command failed

npm error command sh -c nuxt prepare

npm error A complete log of this run can be found in: /vercel/.npm/_logs/2024-12-09T15_32_38_429Z-debug-0.log

Error: Command “npm install” exited with 1

I did the second approach and it built successfully just curious do I need to import that as well?

import { Analytics } from ‘@vercel/analytics/nuxt’

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.