graphql-kit / graphql-voyager

🛰️ Represent any GraphQL API as an interactive graph
https://graphql-kit.com/graphql-voyager/
MIT License
7.74k stars 514 forks source link

Cannot find module 'koa'. #87

Closed anodynos closed 5 years ago

anodynos commented 5 years ago

When importing as mentioned in docs for an express project:

import { express as voyagerMiddleware } from 'graphql-voyager/middleware';

I get

 node_modules/graphql-voyager/middleware/koa.d.ts:1:25 - error TS2307: Cannot find module 'koa'.

 1 import { Context } from 'koa';

from typescript@2.9.2

daniloferreira commented 5 years ago

I facing the same issue. Event though my tsconfig.json ignores node_modules: "exclude": [ "node_modules" ] the error occurs

daniloferreira commented 5 years ago

I realized how make it work: import voyagerMiddleware = require('graphql-voyager/middleware/express'); app.use('/voyager', voyagerMiddleware.default({ endpointUrl: '/graphql' }));

daniloferreira commented 5 years ago

this way worked better: import voyagerMiddleware from 'graphql-voyager/middleware/express'; app.use('/voyager', voyagerMiddleware({ endpointUrl: '/graphql' }));

IvanGoncharov commented 5 years ago

@anodynos @daniloferreira Just published 1.0.0-rc.26 📦 with a fix included. Can you please try.

this way worked better: import voyagerMiddleware from 'graphql-voyager/middleware/express'; app.use('/voyager', voyagerMiddleware({ endpointUrl: '/graphql' }));

@daniloferreira It's workaround not a full fix since express middlaware still depends on @types/express. So I just removed all externall types from middlewares to completely solve this problem.

Apollinaire commented 5 years ago

@IvanGoncharov I get TypeError: voyagerMiddleware is not a function with the following imports on 1.0.0-rc.26 :

import { express as voyagerMiddleware } from 'graphql-voyager/middleware';  // => undefined
//or
import voyagerMiddleware  from 'graphql-voyager/middleware/express'; // => { }
IvanGoncharov commented 5 years ago

@Apollinaire Strange, it works for me when I'm doing:

const { express: voyagerMiddleware } = require('graphql-voyager/middleware');

Can you please test the same code in your setup. I see you are using ES6 modules, what environment do you using babel, typescript, esm?

Apollinaire commented 5 years ago

I'm using Meteor to build, with the ecmascript package, which uses Babel under the hood. To be more precise, i'm trying to include this to vulcan.js : https://github.com/vulcanjs/vulcan Any import on server side returns undefined. On the client it works, but I need the middleware to run serverside only, because that's where I create my express app.

IvanGoncharov commented 5 years ago

@Apollinaire I'm not familiar with meteor so can you please create GitHub repo with the minimal setup to reproduce this issue?

Apollinaire commented 5 years ago

After further search, it seems related to how I build my project. Something in my config must be wrong because I am able to import and run the middleware in other Vulcan/Meteor projects. I'll update this when I've found the issue, it might be useful for future people Thanks for your time @IvanGoncharov

IvanGoncharov commented 5 years ago

@Apollinaire I'm closing this issue since the original issue was resolved. But please post your findings here it will help if other Meteor users will have the same problem.

anodynos commented 5 years ago

@IvanGoncharov thanks, it worked great!

import voyagerMiddleware from 'graphql-voyager/middleware/express'; 
app.use('/voyager', voyagerMiddleware({ endpointUrl: '/graphql' }));
Apollinaire commented 5 years ago

@IvanGoncharov it was just some bad config from me, other should not have the same problem.

SachaG commented 5 years ago

@Apollinaire I'm running into the same issue on my own Vulcan project, how did you fix it?

Apollinaire commented 5 years ago

@SachaG IIRC the problem was that I was doing npm i --save-dev graphql-voyager because I was thinking that I only had to use it on dev environment. But Meteor did not like this, so I just did npm i graphql-voyager and it worked !

SachaG commented 5 years ago

Haha exact same issue for me! Thanks!

eric-burel commented 5 years ago

Guess who got the same issue

Apollinaire commented 5 years ago

Haha exact same issue for me! Thanks!

Guess who got the same issue

We're one damn fine core team for Vulcan.js