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

Cannot read property 'guess' of undefined #83

Closed
ctf0 opened this issue Nov 2, 2018 · 17 comments
Closed

Cannot read property 'guess' of undefined #83

ctf0 opened this issue Nov 2, 2018 · 17 comments

Comments

@ctf0
Copy link

ctf0 commented Nov 2, 2018

am trying to use guess with laravel through a pre-defined routes file like in nuxt example so the setup is

  • guess-routes.json ex.
{
    "\/": {
        "\/login": 2,
        "\/about": 1
    },
    "\/about": {
        "\/contact-us": 1
    },
    "\/contact-us": {
        "\/": 1
    }
}
  • webpack
const {readFileSync} = require('fs')
const {GuessPlugin} = require('guess-webpack')

mix.webpackConfig({
    plugins: [
        new GuessPlugin({
            reportProvider() {
                return Promise.resolve(JSON.parse(readFileSync('./guess-routes.json')))
            }
        })
    ]
})
  • app.js
import {guess} from 'guess-webpack/api'
guess()
  • error
    demo
@mgechev
Copy link
Member

mgechev commented Nov 2, 2018

@daliborgogic do you know what might be going on here?

@daliborgogic
Copy link

@mgechev Yes. guess runs only on client side. In webpack config just add condition @ctf0

@ctf0
Copy link
Author

ctf0 commented Nov 3, 2018

@daliborgogic can u elaborate ? an example might help as well

@daliborgogic
Copy link

daliborgogic commented Nov 3, 2018

I think real problem is in app.js.
This is required because we don't want to run Guess.js on the server

// app.js
if (typeof window !== 'undefined') {
   // Invoke guess() here
}
// Rest of app logic

@ctf0
Copy link
Author

ctf0 commented Nov 3, 2018

actually the check wont make any diff because its a php not a node env but still nothing changed, same error

@mgechev
Copy link
Member

mgechev commented Nov 3, 2018

Would you share a minimum demo where we can reproduce the problem?

@ctf0
Copy link
Author

ctf0 commented Nov 4, 2018

sure, here is a demo repo https://github.com/ctf0/guess-demo
u need laravel & composer installed on ur system

@zipme
Copy link

zipme commented Nov 5, 2018

I have the same issue here with a nuxt project, I am using this module https://github.com/nuxt-community/guess-module

The config in nuxt.config.js is something like:

['@nuxtjs/guess', {
  GA: process.env.GA_VIEW_ID,
  jwt: {
    private_key: process.env.GA_PRIVATE_KEY,
    client_email: process.env.GA_CLIENT_EMAIL
  },
  period: {
    startDate: new Date('2018-09-01'),
    endDate: new Date('2018-10-09')
  },
  runtime: {
    delegate: true,
    prefetchConfig: {
      '4g': 0.3,
      '3g': 0.3,
      '2g': 0.3,
      'slow-2g': 0.3
    }
  }
}],

@daliborgogic
Copy link

@zipme guess-webpack don't have option jwt. Can you share your nuxt.config.js?

@zipme
Copy link

zipme commented Nov 5, 2018

@daliborgogic Hi, I think it does, check this thread #80

@daliborgogic
Copy link

Thanks for point to this thread. Will check if there is any changes in API.

@daliborgogic
Copy link

@zipme Is your GA in format UA-XXXXXXXX-X or XXXXXXXX?

@zipme
Copy link

zipme commented Nov 5, 2018

it's the view id, it's XXXXXXXX

@zipme
Copy link

zipme commented Nov 5, 2018

hi @daliborgogic , after I disabled the pwa and remove all the cache the error seems to be gone, I guess it was the previous cached js caused the issue. Thanks for the help!!

@mgechev
Copy link
Member

mgechev commented Nov 5, 2018

How did you disabled the PWA? Ideally, Guess.js should not interfer with other modules.

@zipme
Copy link

zipme commented Nov 5, 2018

@mgechev I guess the issue I have is that I did some misconfiguration in the nuxt.config, but because of the PWA, the incorrect js file was being loaded even though I adjusted the config file, after I temporarily disabled the pwa module and clear the cache it works.

@ctf0
Copy link
Author

ctf0 commented Nov 7, 2018

@mgechev any news 🎈 ?

@ctf0 ctf0 closed this as completed Jan 1, 2019
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

4 participants