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

Runtime config: Cannot read property 'find' of undefined #141

Open
jeanmatthieud opened this issue Dec 2, 2021 · 5 comments
Open

Runtime config: Cannot read property 'find' of undefined #141

jeanmatthieud opened this issue Dec 2, 2021 · 5 comments

Comments

@jeanmatthieud
Copy link

When I'm using the runtimeConfig property, I get an error on server.js (without callstack):

Cannot read property 'find' of undefined

Config:

gtm: {
  id: "GTM-XXXXXXX",
  enabled: true,
  debug: true,
},
publicRuntimeConfig: {
  gtm: {
    id: process.env.GTM_ID,
  }
}

Nuxt: 2.15.8
Gtm Module: 2.4.0

@zBelguithAccor
Copy link

any update ?

@Quineone
Copy link

Quineone commented Feb 17, 2022

same problem

@Quineone
Copy link

hi @jeanmatthieud , the workaround work for me:

publicRuntimeConfig: {
  GTM_ID: process.env.GTM_ID,
},

gtm: {},

plugins: [
  '~/plugins/gtm.client.ts', // should be loaded in client only,
],

then in the gtm.client.ts

export default function ({ $gtm, $config }) {
  $gtm.init($config.GOOGLE_TAG_MANAGER_ID)
}

@Vicula
Copy link

Vicula commented Apr 27, 2023

Any update on this?

@papasoft23
Copy link

papasoft23 commented Jun 29, 2023

Maybe this will save someones time ;)
I could not manage to make this work with plugin and 2 containers, as described in docs, but moving definition to nodules instead of buildModules made it work for me with 1 container:

modules: [
      [
        '@nuxtjs/gtm',
        {
          enabled: !!GOOGLE_TAG_MANAGER_ID,
          id: GOOGLE_TAG_MANAGER_ID,
          pageTracking: false, // handled by useGoogleTagManager composable
          pageViewEventName: 'pageview',
          debug: !isProd // check if not production env to be save during developement
        }
      ]
],

Also not the best solution, but worked for multiple containers, added plugin to insert js in head and noscript in body:

export default function() {
    // Add additional container script tag to head
    let script = document.createElement("script")
    script.async = true
    script.src = "https://www.googletagmanager.com/gtm.js?id=" + process.env.GOOGLE_TAG_MANAGER_ID_EXTRA
    document.head.appendChild(script)

    // Add additional container <noscrip> tag to body
    let noscript = document.createElement("div")
    noscript.dataset.nHead = "ssr"
    noscript.dataset.pbody = "true"
    noscript.innerHTML = '<noscript><iframe src="https://www.googletagmanager.com/ns.html?id='+ process.env.GOOGLE_TAG_MANAGER_ID_EXTRA + '" height="0" width="0" style="display:none;visibility:hidden" title="gtm"></iframe></noscript>'
    document.body.prepend(noscript)
}

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

5 participants