Error when importing library
Unsolved
Plugin Development
-
Hello !
I follow the doc to import an external library in my plugin (https://github.com/PokeAPI/pokedex-promise-v2)I my library.js, in plugin.init, I add this :
routeHelpers.setupPageRoute(router, '/pokemon/:param1', [(req, res, next) => {
winston.info(`[plugins/pokemon] In middleware. This argument can be either a single middleware or an array of middlewares`); setImmediate(next);
}], async (req, res) => {
const pokemonName = req.params.param1; let pokemonSpec, frenchName require('pokedex-promise-v2', async (Pokedex) => { const P = new Pokedex(); pokemonSpec = await P.getPokemonSpeciesByName(pokemonName); // // pokemonSpec = await P.getCharacteristicById(pokemonName); frenchName = pokemonSpec.names.filter(pokeAPIName => pokeAPIName.language.name === 'fr')[0].name; }); winston.info(`[plugins/pokemon] Navigated to ${nconf.get('relative_path')}/pokemon`); res.render('pokemon', { pokemon: pokemonName, frenchName : frenchName });
});
In plugin.json, I have this
"modules": {
"../client/quickstart.js": "./static/lib/quickstart.js", "../admin/plugins/quickstart.js": "./static/lib/admin.js", "pokedex-promise-v2" : "./node_modules/pokedex-promise-v2"
},
When I try to go on the route, I have this error :
What I am doing wrong ?
-
@Goby03 require doesn't work like like on the server side.
Just put
const Pokedex = require('pokedex-promise-v2');
At the top of the file, then use it later
-
That would be too much work, can you use an older version of 'pokedex-promise-v2' that allows commonjs usage.
Also what happened when you used.
const Pokedex = await import('pokedex-promise-v2'); const P = new Pokedex();
Are you seeing any error messages or is it just not returning anything in
Pokedex
?
Copyright © 2024 NodeBB | Contributors