0

I want to use the pokedex-promise for a pokemonapi but the docs only show you how to require it in vanilla javascript style:

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

How do I use import to get this module? I've tried

import {Pokedex} from 'pokedex-promise-v2' 

and

import Pokedex from 'pokedex-promise-v2' 

but both throw errors with the module:

in ./~/tough-cookie/package.json Module parse failed: /Users/jlei/Desktop/pokeapp/node_modules/tough-cookie/package.json Unexpected token (2:9) You may need an appropriate loader to handle this file type. SyntaxError: Unexpected token (2:9) at Parser.pp$4.raise (/Users/jlei/Desktop/pokeapp/node_modules/acorn/dist/acorn.js:2221:15) at Parser.pp.unexpected (/Users/jlei/Desktop/pokeapp/node_modules/acorn/dist/acorn.js:603:10) at Parser.pp.semicolon (/Users/jlei/Desktop/pokeapp/node_modules/acorn/dist/acorn.js:581:61) at Parser.pp$1.parseExpressionStatement (/Users/jlei/Desktop/pokeapp/node_modules/acorn/dist/acorn.js:966:10) at Parser.pp$1.parseStatement (/Users/jlei/Desktop/pokeapp/node_modules/acorn/dist/acorn.js:730:24) at Parser.pp$1.parseBlock (/Users/jlei/Desktop/pokeapp/node_modules/acorn/dist/acorn.js:981:25) at Parser.pp$1.parseStatement (/Users/jlei/Desktop/pokeapp/node_modules/acorn/dist/acorn.js:709:33) at Parser.pp$1.parseTopLevel (/Users/jlei/Desktop/pokeapp/node_modules/acorn/dist/acorn.js:638:25) at Parser.parse (/Users/jlei/Desktop/pokeapp/node_modules/acorn/dist/acorn.js:516:17) at Object.parse (/Users/jlei/Desktop/pokeapp/node_modules/acorn/dist/acorn.js:3098:39) @ ./~/tough-cookie/lib/cookie.js 38:14-40 
4
  • I think your code is not transpiring properly. can you share transpiler code part. nd mention the error in the question. Commented Aug 30, 2016 at 0:51
  • what is the transpiler code part? is that something from babel? i've added the error Commented Aug 30, 2016 at 0:58
  • you need to use webpack or gulp or anything for that purpose. Commented Aug 30, 2016 at 1:03
  • 1
    It seems you are using webpack. Some code is trying to include a package.json file. In order for this to work you have to configure json-loader or configure webpack to ignore that file. The error has nothing to do with the code you posted. Commented Aug 30, 2016 at 1:31

1 Answer 1

1

You need to add the json-loader for webpack. Install via NPM:

npm install --save json-loader 

Then add it to your webpack config like so:

module: { loaders: [ /* ...other loaders */ { test: /\.json$/, loader: 'json', }, ], }, 

This will allow webpack to load the json file when it's bundling.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.