PokeAPI / pokedex-promise-v2

An easy way to use pokeapi v2 with promises in node.js
MIT License
510 stars 89 forks source link

Can't read property "prototype" of undefined #27

Closed mjatt closed 7 years ago

mjatt commented 7 years ago

I've used npm rebuild, updated pokedex, but still getting the following error: https://gyazo.com/e438ba5feab5c8a8c22e06d6985e5d5a I've messaged "The Coding Den", who advised me to raise this issue.

The exact same command works on the npm browser attachment, but not in this.

Naramsim commented 7 years ago

Which Node and Npm are you using? Node 8?

On Jun 23, 2017 13:20, "Matt Taggart" notifications@github.com wrote:

I've used npm rebuild, updated pokedex, but still getting the following error: https://gyazo.com/e438ba5feab5c8a8c22e06d6985e5d5a I've messaged "The Coding Den", who advised me to raise this issue.

The exact same command works on the npm browser attachment, but not in this.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PokeAPI/pokedex-promise-v2/issues/27, or mute the thread https://github.com/notifications/unsubscribe-auth/AIlFrDo6gjXpjRWP0l4KHTPdyWaCOUTYks5sG59xgaJpZM4ODckC .

mjatt commented 7 years ago

Tried on Node 7.9.0 and 8.1.2

mjatt commented 7 years ago

Sorry, tried on npm 4.2.0 and 5.0.3

Naramsim commented 7 years ago

Hey, @mjatt, I really can't understand why you have that error, I tried to test this script with Node latest and Npm latest, and it gave me no error.

app.js

var Pokedex = require('pokedex-promise-v2');
var P = new Pokedex();

exports.run = () => {
    P.getPokemonByName('eevee') // with Promise
    .then(function(response) {
      console.log(response);
    })
    .catch(function(error) {
      console.log('There was an ERROR: ', error);
    });
}

call.js

var app= require("./app.js")
app.run();

node call.js gives me no error. Maybe the fault is not in our wrapper. When removing the Pokedex call from your run function, does it still give the error?

PS: try to create the Pokedex instance with this object:

var Pokedex = require('pokedex-promise-v2');
var options = {
  cacheLimit: 0
}
var P = new Pokedex(options);
mjatt commented 7 years ago

Hi there.

I tried the cacheLimit suggestion and got the same error.

When I remove all Pokedex features, everything works successfully. https://gyazo.com/f39c0ffeb0272238e361bbe38abf4828 However even when I just include the declaration of Pokedex and the wrapper it still fails? https://gyazo.com/800f08c66857bcb41fdbfd76d5ba4ff1

This may be my error, but I'm failing to see where the problem is too.

mjatt commented 7 years ago

Hi again,

I've just tried a basic

var Pokedex = require('pokedex-promise-v2');
var MyPokedex = new Pokedex();

MyPokedex.getPokemonByName('eevee').then(function (response) {
  console.log(response);
}).catch(function (error) {
  console.log(error);
}); 

This was in another folder with the pokedex being the only extra module. This worked fine. However, I was using this for a Discord bot which is wanting to be exported.

Naramsim commented 7 years ago

Ok, fine.

Can you copy-paste here the full log? In your picture, some lines are truncated

Now, this is a workaround that could fit: instead of using this wrapper, try https://github.com/PokeAPI/pokeapi-js-wrapper

Use it like:

var Pokedex = require('pokeapi-js-wrapper');
var P = new Pokedex.Pokedex();
P.getPokemonByName('eevee') // with Promise
    .then(function(response) {
      console.log(response);
    })
mjatt commented 7 years ago

D:\Users\mtaggart\Desktop\NelsonManbot>node mjattbot.js
Client launched at Fri Jun 23 2017 15:27:37 GMT+0100 (GMT Daylight Time)
TypeError: Cannot read property 'prototype' of undefined
    at module.exports (D:\Users\mtaggart\Desktop\NelsonManbot\node_modules\request-promise-core\configure\request2.js:34:47)
    at Object.<anonymous> (D:\Users\mtaggart\Desktop\NelsonManbot\node_modules\request-promise\lib\rp.js:28:1)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at o (D:\Users\mtaggart\Desktop\NelsonManbot\node_modules\pokedex-promise-v2\index.js:1:209)
    at Object.<anonymous> (D:\Users\mtaggart\Desktop\NelsonManbot\node_modules\pokedex-promise-v2\index.js:1:582)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (D:\Users\mtaggart\Desktop\NelsonManbot\commands\pokemon.js:2:15)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)

full log ^ I'll give that wrapper a go EDIT: The suggested wrapper works perfectly. Thanks; I'll use this for now.

Naramsim commented 7 years ago

I see that you are using request@~2.16.6 but our wrapper requires a newer version of it.

Can u npm i request?

Naramsim commented 7 years ago

Hey, @mjatt please, can you verify if installing a newer version of request, the wrapper works? Just run the command above and revert the old code with the old wrapper.

If it works I can close the issue, and you will benefit of resource caching

mjatt commented 7 years ago

Hi there.

Your suggestion worked. Thanks for sitting through it with me, and apologies for wasting your time.

Regards,