ethanresnick / json-api-example

An example API created with my JSON-API library (http://github.com/ethanresnick/json-api)
31 stars 15 forks source link

Cannot read property 'buildRequestObject' of undefined #16

Closed ghost closed 6 years ago

ghost commented 6 years ago

Tiny glitch project: https://glitch.com/edit/#!/discord-finder

I am trying to use this to make an API.

Going to e.g. https://discord-finder.glitch.me/api results in the error


TypeError: Cannot read property 'buildRequestObject' of undefined
    at docsRequest (/rbd/pnpm-volume/da8b9987-0c87-4dc1-9e58-c956dc55452e/node_modules/.registry.npmjs.org/json-api/2.16.5/node_modules/json-api/build/src/http-strategies/Express.js:20:14)
    at Layer.handle [as handle_request] (/rbd/pnpm-volume/da8b9987-0c87-4dc1-9e58-c956dc55452e/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/router/layer.js:95:5)
    at next (/rbd/pnpm-volume/da8b9987-0c87-4dc1-9e58-c956dc55452e/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/rbd/pnpm-volume/da8b9987-0c87-4dc1-9e58-c956dc55452e/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/rbd/pnpm-volume/da8b9987-0c87-4dc1-9e58-c956dc55452e/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/router/layer.js:95:5)
    at /rbd/pnpm-volume/da8b9987-0c87-4dc1-9e58-c956dc55452e/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/rbd/pnpm-volume/da8b9987-0c87-4dc1-9e58-c956dc55452e/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/router/index.js:335:12)
    at next (/rbd/pnpm-volume/da8b9987-0c87-4dc1-9e58-c956dc55452e/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/router/index.js:275:10)
    at router.use (/app/routes/api.js:31:3)
    at Layer.handle [as handle_request] (/rbd/pnpm-volume/da8b9987-0c87-4dc1-9e58-c956dc55452e/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/rbd/pnpm-volume/da8b9987-0c87-4dc1-9e58-c956dc55452e/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/router/index.js:317:13)
    at /rbd/pnpm-volume/da8b9987-0c87-4dc1-9e58-c956dc55452e/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/rbd/pnpm-volume/da8b9987-0c87-4dc1-9e58-c956dc55452e/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/router/index.js:335:12)
    at next (/rbd/pnpm-volume/da8b9987-0c87-4dc1-9e58-c956dc55452e/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/router/index.js:275:10)
    at Function.handle (/rbd/pnpm-volume/da8b9987-0c87-4dc1-9e58-c956dc55452e/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/router/index.js:174:3)
    at router (/rbd/pnpm-volume/da8b9987-0c87-4dc1-9e58-c956dc55452e/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/router/index.js:47:12)```

Instead of showing the auto-generated docs as I'd expect.
ethanresnick commented 6 years ago

I think the issue is that your package.json is referencing an old version of the json-api library (v2), whereas this example repo, and the docs on the main json-api repo, are based on v3. Try upgrading to the latest v3 release and lmk if that fixes it.

ghost commented 6 years ago

@ethanresnick What do I need to change "json-api": "^2.16.5"to?

I tried

$ npm install --save json-api@next
npm ERR! code ETARGET
npm ERR! notarget No matching version found for json-api@next
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

So what should I change my package.json to?

ghost commented 6 years ago

I did npm install --save json-api@3.0.0-rc.4.0.1 and now it seems to work fine.

The package.json looks like

   "json-api": "^3.0.0-rc.4.0.1"
ethanresnick commented 6 years ago

Glad to hear it