Home  >  Q&A  >  body text

SDK integration error with Axeptio in Nuxt3

I am currently developing a Nuxt3 project and need to integrate the scripts provided by Axeptio (cookie platform).

I made the Nuxt3 plugin to use their script integration

export default defineNuxtPlugin((useNuxtApp) => {
  ;(<any>window).axeptioSettings = {
    clientId: '...',
    cookiesVersion: '...',
  }

  ;(function (d, s) {
    var t:any = d.getElementsByTagName(s)[0],
      e: any = d.createElement(s)
    e.async = true
    e.src = '//static.axept.io/sdk.js'
    t.parentNode.insertBefore(e, t)
  })(document, 'script')
})

But this will throw

Uncaught TypeError: Cannot read attribute of undefined (read 'REACT_APP_SC_ATTR')

So I tried it in Nuxt2 and it worked fine.

What should I do to make it work?

P粉396248578P粉396248578164 days ago462

reply all(1)I'll reply

  • P粉578343994

    P粉5783439942024-03-28 11:48:18

    Nuxt3 is based on Vite and therefore does not use process.env as Webpack4 does (in Nuxt2).
    This is how to access environment variables in Nuxt3 by using import.meta.env.YOUR_COOL_ENV_VAR.

    reply
    0
  • Cancelreply