question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unable to compile TS app - missing @types/type-is apollo-server-express

See original GitHub issue

After installing apollo-server-express and running tsc to compile the app i get the following error:

Error: Command failed with exit code 2: ./node_modules/.bin/tsc -p tsconfig.build.json
node_modules/apollo-server-express/src/ApolloServer.ts(20,20): error TS7016: Could not find a declaration file for module 'type-is'. '/Users/fabriziofenoglio/Documents/gg/node_modules/type-is/index.js' implicitly has an 'any' type.
  Try `npm install @types/type-is` if it exists or add a new declaration (.d.ts) file containing `declare module 'type-is';`
    at makeError

I can manually solve this by installing @types/type-is but, this surely should be included in the devDependencies of apollo-server-express

apollo-server-express version: ^2.9.16

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bwltcommented, Aug 24, 2020

Hi, this is a reproduction of the above error: https://github.com/bwlt/apollo-server/tree/repro-3691 I’m having the same issue. The scenario is:

// main.ts
import { ApolloServer } from "apollo-server";
import { context } from "./context";
import { typeDefs } from "./schema";
import { resolvers } from "./resolvers";
import { mocks } from "./mocks";

const server = new ApolloServer({
  typeDefs,
  resolvers,
  context,
  mocks: process.env.NODE_ENV === "production" ? undefined : mocks,
});
// context.ts
import { ExpressContext } from "apollo-server-express/src/ApolloServer";

export interface Context extends ExpressContext {
  ...
}

export const context: ContextFunction<
  ExpressContext,
  Context
> = function context(expressContext) {
  ...
}

The problem occurs when I import { ExpressContext } from “apollo-server-express/src/ApolloServer”.

Replacing

import { ExpressContext } from "apollo-server-express/src/ApolloServer";

with

import { ExpressContext } from "apollo-server-express/dist/ApolloServer";

will fix the issue

0reactions
glassercommented, Sep 30, 2021

Importing from package/src/somefile or package/dist/somefile is not officially supported. We do our best to choose what gets exported from the top level of a package and everything inside is an implementation detail. (Some other Apollo projects like Apollo Client explicitly set up deeper exports, but Apollo Server doesn’t.)

The symbol in question ExpressContext has been exported from apollo-server-express since v2.19.2, so you can now just do import { ExpressContext } from 'apollo-server-express' and it should just work. (I looked at the reproduction, upgraded it to v2.19.2 and changed the import line, and it worked. It also works with 3.3.0.)

@shellscape , are you running into this with the same symbol or a different one?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: TSError: Unable to compile TypeScript - Stack Overflow
I had met same issue. First I remove ts-node and typescript from package.json . then, npm install ts-node --save-dev npm install typescript ......
Read more >
Build a GraphQL app in Node.js with TypeScript and graphql ...
In this article, we will build a full-stack app using GraphQL and TypeScript. Here, we will use the apollo-server-express package to build a ......
Read more >
Apollo Server Express 3 With TypeScript - rockyourcode
Compiled files (from TypeScript to JavaScript) will land in the dist folder. You can find more details in the links at the end...
Read more >
How To Run TypeScript Scripts with ts-node - DigitalOcean
With TypeScript being a superset of JavaScript, using it means compiling your TypeScript files down to pure JavaScript before the V8 engine can ......
Read more >
Nuxt 3 build logs "unable to compile TypeScript" - Support
App on Netlify https://courageous-fox-6869a5.netlify.app Code on Github https://github.com/p3t3r67x0/nuxt-rc-netlify Issue on Build Nuxt 3 build fails as it ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found