krakenjs / post-robot

Cross domain post-messaging on the client side using a simple listener/client pattern.
Apache License 2.0
736 stars 92 forks source link

WeakMap expected key #119

Open kevcomparadise opened 6 months ago

kevcomparadise commented 6 months ago

Hello,

I've been using PostRobot for a while. I use it to communicate with my application when implementing it in an iframe. I am on Nuxt2, and it works very well.

I am currently migrating to Nuxt3 and encountering an issue. When importing the library (on the client side), I get an error like this:

"WeakMap expected key." at _proto.has (http://localhost:3000/_nuxt/node_modules/.cache/vite/client/deps/post-robot.js?v=de6bb484:931:21) at _proto.getOrSet (http://localhost:3000/_nuxt/node_modules/.cache/vite/client/deps/post-robot.js?v=de6bb484:950:22) at getStore (http://localhost:3000/_nuxt/node_modules/.cache/vite/client/deps/post-robot.js?v=de6bb484:1262:31) at Object.getOrSet (http://localhost:3000/_nuxt/node_modules/.cache/vite/client/deps/post-robot.js?v=de6bb484:1280:38) at addRequestListener (http://localhost:3000/_nuxt/node_modules/.cache/vite/client/deps/post-robot.js?v=de6bb484:2212:53) at on_on (http://localhost:3000/_nuxt/node_modules/.cache/vite/client/deps/post-robot.js?v=de6bb484:2237:12) at http://localhost:3000/_nuxt/node_modules/.cache/vite/client/deps/post-robot.js?v=de6bb484:2527:32 at util_getOrSet (http://localhost:3000/_nuxt/node_modules/.cache/vite/client/deps/post-robot.js?v=de6bb484:1121:21) at Object.getOrSet (http://localhost:3000/_nuxt/node_modules/.cache/vite/client/deps/post-robot.js?v=de6bb484:1238:24) at http://localhost:3000/_nuxt/node_modules/.cache/vite/client/deps/post-robot.js?v=de6bb484:2526:47

I don't understand why, as I have the window variable accessible.

Thank you for your help.

pegiadise commented 5 months ago

Same issue. Can work around it via if you import the browser version directly. Hope it saves some time to someone.

  // nuxt.config.ts
  app: {
    head: {
      // make sure to match your iframe version, @krakenjs scoped package doesn't work with this one...
      script: [{ src: 'https://unpkg.com/post-robot@10.0.46/dist/post-robot.min.js' }], 
    },
  },
// global.d.ts at root nuxt folder
import PostRobot from 'post-robot'

export {}

declare global {
  interface Window {
    __NUXT__: any
    postRobot: typeof PostRobot
  }
}