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

Uncaught ReferenceError: defineNuxtPlugin is not defined #360

Open
devonik opened this issue Sep 22, 2023 · 15 comments
Open

Uncaught ReferenceError: defineNuxtPlugin is not defined #360

devonik opened this issue Sep 22, 2023 · 15 comments

Comments

@devonik
Copy link

devonik commented Sep 22, 2023

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

import { defineNuxtPlugin } from '#app'

@sangyookm
Copy link

Experiencing the same thing.

@mbaev
Copy link

mbaev commented Jan 6, 2024

Same thing, seems to be an issue.

@mbaev
Copy link

mbaev commented Jan 6, 2024

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`

@armenr
Copy link

armenr commented Jan 14, 2024

I'm having the same issue.

@armenr
Copy link

armenr commented Jan 14, 2024

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.

@kambanwait
Copy link

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

@richard-edwards
Copy link

I'm getting the error as well.

@richard-edwards
Copy link

@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'
      })
      ```
 

@aguirremac
Copy link

getting the same issue

@aguirremac
Copy link

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

@richard-edwards
Copy link

@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>

@aguirremac
Copy link

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.

@thiagonunesbatista
Copy link

thiagonunesbatista commented Mar 17, 2024

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

@armenr
Copy link

armenr commented Mar 17, 2024

@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 :)

@GrantlyNeely
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants