logrocket icon indicating copy to clipboard operation
logrocket copied to clipboard

Uncaught ReferenceError: defineNuxtPlugin is not defined

Open devonik opened this issue 1 year ago • 15 comments

I think you have to explicit import defineNuxtPlugin like you import Logrocket in the plugin

import { defineNuxtPlugin } from '#app'

devonik avatar Sep 22 '23 12:09 devonik

Experiencing the same thing.

sangyookm avatar Oct 16 '23 18:10 sangyookm

Same thing, seems to be an issue.

mbaev avatar Jan 06 '24 08:01 mbaev

For those who curious the error is: image

After executing

npm i nuxt-logrocket

and adding config

// nuxt.config.js

export default defineNuxtConfig({
  modules: [
    'nuxt-logrocket',
    //...
  ],
  logRocket: {
    id: 'xxx',
    dev: true,
    config: {}
  },
  //...
});

Nuxt info:

- Operating System: `Darwin`
- Node Version:     `v20.6.1`
- Nuxt Version:     `3.8.0`
- CLI Version:      `3.9.1`
- Nitro Version:    `2.7.2`
- Package Manager:  `[email protected]`
- Builder:          `-`
- User Config:      `ssr`, `devtools`, `typescript`, `app`, `build`, `buildModules`, `modules`, `compilerOptions`, `vite`, `hooks`, `runtimeConfig`, `inlineSSRStyles`
- Runtime Modules:  `[email protected]`, `@pinia/[email protected]`, `@nuxtjs/[email protected]`, `[email protected]`, `@nuxtjs/[email protected]`
- Build Modules:    `@nuxtjs/svg`

mbaev avatar Jan 06 '24 08:01 mbaev

I'm having the same issue.

armenr avatar Jan 14 '24 18:01 armenr

For anyone else that's stuck, this seems to work, for now. I did this quick & dirty, but if you're running Nuxt3, with the latest pinia and the latest logrocket npm packages, you should be ok, I think.

plugins/00.logRocket.client.ts

import LogRocket from 'logrocket'
import type { Plugin as NuxtPlugin } from '#app'

const plugin: NuxtPlugin = defineNuxtPlugin(() => {
  const { $pinia } = useNuxtApp()
  const opts = useRuntimeConfig()?.public?.logRocket

  if (!opts?.id || (!opts?.dev && !(process.env.NODE_ENV === 'production')))
    return

  LogRocket.init(opts?.id, opts?.config)

  if ($pinia && opts?.enablePinia) {
    $pinia.use(({ store }) => {
      store.$subscribe(m => LogRocket.log('mutation', m))
    })
  }

  return { provide: { LogRocket } }
})

export default plugin

And in your nuxt.config.ts, you should have this:

  runtimeConfig: {
    public: {
      // all options can be found here: https://www.npmjs.com/package/logrocket?activeTab=code
      // dist/types.d.ts --> interface IOptions
      logRocket: {
        id: 'som_id/your_logrocket_appName',
        dev: false, // or true if you want
        enablePinia: true,
        config: {},
      },
    },
  },

Hope this helps. It's pretty much the full re-implementation of this repo's plugin...except up-to-date and properly typed.

armenr avatar Jan 14 '24 19:01 armenr

Just adding a comment here just so it's known that it's still an issue. I have set enablePinia to false and still get the error

kambanwait avatar Feb 26 '24 10:02 kambanwait

I'm getting the error as well.

richard-edwards avatar Mar 08 '24 14:03 richard-edwards

@armenr Just a note to watch for filenames that contain log and are excluded by a .gitignore rule. Caught me when I pushed to production and the plugin wasn't there at all :) Thanks for the help. It's working well.

Only thing I added was LogRocket identity tracking.

      // track user in LogRocket
      LogRocket.identify(user.id.toString(), {
        name: user.name,
        email: user.email,
        // Add your own custom user variables here, ie:
        // subscriptionType: 'pro'
      })
      ```
 

richard-edwards avatar Mar 08 '24 15:03 richard-edwards

getting the same issue

aguirremac avatar Mar 13 '24 09:03 aguirremac

hi @richard-edwards, can you show me how you implemented it in you nuxt.config file please?

aguirremac avatar Mar 13 '24 11:03 aguirremac

@aguirremac assuming you mean the user identification part .. the plugin part is the same as @armenr shows above.

At the top of my app.vue I added the following. I'm not 100% sure that it's the correct way to do it but it seems to be getting me some of the sessions attached to real users. Still in alpha stage so only have a few people testing it. Important part here is that this has to be run on client only thus the if (process.client) { check.

<script setup lang="ts">
  import LogRocket from 'logrocket'
  const { user } = useUserStore()
  if (process.client) {
    // track user in LogRocket
    if (user) {
      LogRocket.identify(user.id.toString(), {
        name: user.name,
        email: user.email
        // Add your own custom user variables here, ie:
        // subscriptionType: 'pro'
      })
    }
  }
</script>

richard-edwards avatar Mar 13 '24 12:03 richard-edwards

import LogRocket from 'logrocket' const { user } = useUserStore() if (process.client) { // track user in LogRocket if (user) { LogRocket.identify(user.id.toString(), { name: user.name, email: user.email // Add your own custom user variables here, ie: // subscriptionType: 'pro' }) } }

thank you.

aguirremac avatar Mar 14 '24 16:03 aguirremac

The same error happens here when adding the LogRocket module in nuxt.config.ts.

export default defineNuxtConfig({
  devtools: { enabled: true },
  modules: [
    'nuxt-feather-icons',
    'nuxt-gtag',
    'nuxt-icon',
    'nuxt-simple-robots',
    'nuxt-logrocket',
    '@nuxtjs/sitemap'
  ],
  logRocket: {
    id: process.env.LOGROCKET_APP_ID,
    dev: process.env.NODE_ENV !== 'production',
    config: {}
  },
  ......
})

When I Look at the browser console I see an error message:

image

thiagonunesbatista avatar Mar 17 '24 19:03 thiagonunesbatista

@thiagonunesbatista - Please see the posts above. We solved this by simply reimplementing the correct code for the plugin, ourselves.

Feel free to use the examples included here. They have been working for the rest of us :)

armenr avatar Mar 17 '24 20:03 armenr

I am running into this issue as well. It seems like the only solution currently is to rewrite defineNuxtPlugin() ? I'm running Nuxt3. Is this plugin generally still supported / active?

GrantlyNeely avatar Aug 05 '24 17:08 GrantlyNeely