Closed dsebastien closed 5 years ago
Nice fix! I agree, I wish there was better Typescript support.
I'm not sure that I follow ā shouldn't we support import
if your TS/Node is otherwise set up to support it?
I'll note that I saw a version of this error myself while working on creating apollo-cache-control@0.1.0 but it resolved itself after... running npm install
inside apollo-server-core. I thought maybe it was just an artifact of our lerna setup but if it's affecting end users, that's an issue.
I fixed it by installing the types for graphql
npm i --save-dev @types/graphql
Can anyone confirm that this is still a problem for them with Apollo Server 2?
While this issue has a number of up-votes, it's gone otherwise silent and it's hard to determine if this problem is still affecting users so we can prioritize accordingly.
Feedback would be appreciated!
Sounds like this has been resolved. Let us know if this is still an issue. Thanks!
@abernix I just got this issue and fixed it using whatupdave's solution. It seems it could be easily fixable by just including @types/graphql as a dependency for the cache-control package?
Same thing here as @AleksandarFaraj describes. Using apollo-server 2.1.0
.
This fixed my issue! Thank you so much @dsebastien!
Installing the types as mentioned above fixes the issue.
This is still a problem for me "apollo-server-express": "^2.1.0" "typescript": "^3.1.2" "@types/graphql": "^14.0.3",
NEED HELP
Here's the output of my linting tsc
, even after installing @types/graphql
:
node_modules/apollo-server-core/dist/types.d.ts:4:8 - error TS1192: Module '"/path/to/graphql-servera/node_modules/@types/ws/index"' has no default export.
4 import WebSocket from 'ws';
~~~~~~~~~
node_modules/apollo-server-express/dist/ApolloServer.d.ts:1:8 - error TS1192: Module '"/path/to/graphql-server/node_modules/@types/express/index"' has no default export.
1 import express from 'express';
~~~~~~~
node_modules/apollo-server-express/dist/ApolloServer.d.ts:2:8 - error TS1192: Module '"/path/to/graphql-server/node_modules/@types/cors/index"' has no default export.
2 import corsMiddleware from 'cors';
Adding "skipLibCheck": true,
has helped as a workaround, but the issue is still topical.
Same problem as @kachkaev
+1
Same problem as @kachkaev.Any one can help ?
+1 same problem. excuse my ignorance, but what does skipLibCheck do and why does it work?
+1
+1
I fixed it by installing the types for graphql
npm i --save-dev @types/graphql
Thank you :pray:
Adding @types/graphql didn't work for me, but as found here: https://github.com/apollographql/apollo-server/issues/669
The solution was to setĀ "moduleResolution": "node"Ā atĀ tsconfig.json
Hello!
The fix for the problem is to install @type/graphql.
However, I realized that the latest versions of @ types / graphql completely removed the type definitions, which became part of the graphql package. If you download the most current version you will see that it is empty and contains no definition. Then install the version:
npm install@types/graphql@14.2.3
Hope this helps.
Adding @types/graphql didn't work for me, but as found here: #669
The solution was to setĀ "moduleResolution": "node"Ā atĀ tsconfig.json
Hello!
The fix for the problem is to install @type/graphql.
However, I realized that the latest versions of @ types / graphql completely removed the type definitions, which became part of the graphql package. If you download the most current version you will see that it is empty and contains no definition. Then install the version:
npm install@types/graphql@14.2.3
Hope this helps.
Neither of these worked for me :man_shrugging:
@rob137
Run command:
npm install @types/graphql@14.2.3
?
Please show me error in screen.
Similar to @kachkaev, I got this error when running in debug
mode in VS Code:
node_modules/apollo-server-express/dist/ApolloServer.d.ts:1:8 - error TS1259: Module '"/path/to/apollo-server-express/node_modules/@types/express/index"' can only be default-imported using the 'esModuleInterop' flag
1 import express from 'express';
~~~~~~~
node_modules/apollo-server-express/node_modules/@types/express/index.d.ts:108:1
108 export = e;
~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.
node_modules/apollo-server-express/dist/ApolloServer.d.ts:2:8 - error TS1259: Module '"/path/to/node_modules/@types/cors/index"' can only be default-imported using the 'esModuleInterop' flag
2 import corsMiddleware from 'cors';
~~~~~~~~~~~~~~
/path/to/@types/cors/index.d.ts:34:1
34 export = e;
~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.
Interstingly it worked fine when I ran the application from terminal, so it was only in VS Code debug mode that was causing problems.
Like @kachkaev, my workaround was to add "skipLibCheck": true
to tsconfig.json
Received this error too and ended up with the following:
node_modules/apollo-server-express/node_modules/@types/express/index.d.ts:98:50 - error TS2694: Namespace '"/node_modules/@types/express-serve-static-core/index"' has no exported member 'Params'.
98 interface ErrorRequestHandler<P extends core.Params = core.ParamsDictionary> extends core.ErrorRequestHandler<P> { }
~~~~~~
node_modules/apollo-server-express/node_modules/@types/express/index.d.ts:98:64 - error TS2694: Namespace '"/node_modules/@types/express-serve-static-core/index"' has no exported member 'ParamsDictionary'.
98 interface ErrorRequestHandler<P extends core.Params = core.ParamsDictionary> extends core.ErrorRequestHandler<P> { }
~~~~~~~~~~~~~~~~
node_modules/apollo-server-express/node_modules/@types/express/index.d.ts:98:90 - error TS2315: Type 'ErrorRequestHandler' is not generic.
98 interface ErrorRequestHandler<P extends core.Params = core.ParamsDictionary> extends core.ErrorRequestHandler<P> { }
~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/apollo-server-express/node_modules/@types/express/index.d.ts:107:38 - error TS2694: Namespace '"/node_modules/@types/express-serve-static-core/index"' has no exported member 'Params'.
107 interface Request<P extends core.Params = core.ParamsDictionary> extends core.Request<P> { }
~~~~~~
node_modules/apollo-server-express/node_modules/@types/express/index.d.ts:107:52 - error TS2694: Namespace '"/node_modules/@types/express-serve-static-core/index"' has no exported member 'ParamsDictionary'.
107 interface Request<P extends core.Params = core.ParamsDictionary> extends core.Request<P> { }
~~~~~~~~~~~~~~~~
node_modules/apollo-server-express/node_modules/@types/express/index.d.ts:107:78 - error TS2315: Type 'Request' is not generic.
107 interface Request<P extends core.Params = core.ParamsDictionary> extends core.Request<P> { }
~~~~~~~~~~~~~~~
node_modules/apollo-server-express/node_modules/@types/express/index.d.ts:108:45 - error TS2694: Namespace '"/node_modules/@types/express-serve-static-core/index"' has no exported member 'Params'.
108 interface RequestHandler<P extends core.Params = core.ParamsDictionary> extends core.RequestHandler<P> { }
~~~~~~
node_modules/apollo-server-express/node_modules/@types/express/index.d.ts:108:59 - error TS2694: Namespace '"/node_modules/@types/express-serve-static-core/index"' has no exported member 'ParamsDictionary'.
108 interface RequestHandler<P extends core.Params = core.ParamsDictionary> extends core.RequestHandler<P> { }
~~~~~~~~~~~~~~~~
node_modules/apollo-server-express/node_modules/@types/express/index.d.ts:108:85 - error TS2315: Type 'RequestHandler' is not generic.
108 interface RequestHandler<P extends core.Params = core.ParamsDictionary> extends core.RequestHandler<P> { }
~~~~~~~~~~~~~~~~~~~~~~
node_modules/apollo-server-express/node_modules/@types/express/index.d.ts:110:54 - error TS2315: Type 'Response' is not generic.
110 export interface Response<ResBody = any> extends core.Response<ResBody> { }
After a while of debugging, trying various types.. I ended up just adding skipLibCheck: true to my tsconfig.json file.. which seems quite wrong.
My full tsconfig.json file:
{
"compilerOptions": {
"skipLibCheck": true,
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"sourceMap": true,
"outDir": "./dist",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
},
"exclude": ["node_modules", "src/migrations"]
}
@farukbigez graphqlExpress
is from Apollo Server 1.x. It hasn't been exported from that module ever since 2.0 was released. See a recent getting started section in our documentation for 2.x. If you're migrating from 1.x, see the migration guide.
@hwillson This is still a problem on apollo server 2.16.1
.
> nichehacks-api@0.0.0 build /home/jacob/code/nichehacks/nichehacks-api
> nest build
node_modules/apollo-server-core/dist/ApolloServer.d.ts:5:8 - error TS1259: Module '"/home/jacob/code/nichehacks/nichehacks-api/node_modules/@types/ws/index"' can only be default-imported using the 'esModuleInterop' flag
5 import WebSocket from 'ws';
~~~~~~~~~
node_modules/@types/ws/index.d.ts:265:1
265 export = WebSocket;
~~~~~~~~~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.
Found 1 error(s).
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nichehacks-api@0.0.0 build: `nest build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nichehacks-api@0.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/jacob/.npm/_logs/2020-09-21T19_21_36_909Z-debug.log
Can't build without skipLibCheck
set to true, which is dangerous and ill advised.
During the build process of the app I get the following error:
node_modules/apollo-server-express/node_modules/apollo-server-core/dist/plugin/index.d.ts:1:13 error TS1005: '=' expected.
I have not found the fix for this yet, I've deleted node_modules folder and package-lock.json but still not working.
It would be nice to have some help....
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"outDir": "./dist",
"declaration": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts",
"**/*.test.ts"
]
}
package.json
"dependencies": {
"@apollo/federation": "^0.10.2",
"@types/bluebird": "^3.5.27",
"@types/cookie-parser": "^1.4.2",
"@types/jest": "^24.0.19",
"@types/mysql": "^2.15.7",
"@types/nanoid": "^2.0.0",
"@types/node": "^14.10.1",
"@types/umzug": "^2.2.2",
"@types/validator": "^10.11.3",
"apollo-cache-control": "^0.10.0",
"apollo-cache-inmemory": "^1.6.6",
"apollo-client": "^2.6.4",
"apollo-datasource-rest": "^0.6.1",
"apollo-link": "^1.2.12",
"apollo-link-context": "^1.0.20",
"apollo-link-http": "^1.5.17",
"apollo-link-rest": "^0.7.3",
"apollo-link-schema": "^1.2.3",
"apollo-server": "^2.12.0",
"apollo-server-express": "^2.12.0",
"apollo-server-plugin-response-cache": "^0.3.1",
"apollo-server-testing": "^2.9.0",
"axios": "^0.19.2",
"cookie-parser": "^1.4.4",
"cron": "^1.7.2",
"elastic-apm-node": "^3.3.0",
"express": "^4.17.1",
"express-graphql": "^0.9.0",
"graphql": "^14.5.8",
"graphql-import": "^0.7.1",
"graphql-schema-linter": "^0.2.1",
"jsonwebtoken": "^8.5.1",
"jwk-to-pem": "^2.0.3",
"kafka-node": "^4.1.3",
"link": "^0.1.5",
"log4js": "^5.0.0",
"mysql2": "^1.7.0",
"nanoid": "^3.1.7",
"node": "^14.5.0",
"node-cache": "^5.1.1",
"node-fetch": "^2.6.0",
"promise-retry": "^1.1.1",
"rimraf": "^3.0.0",
"save": "^2.4.0",
"sequelize": "^5.19.5",
"sequelize-cli": "^5.5.1",
"soap": "^0.30.0",
"ts-jest": "^24.1.0",
"typescript": "^3.6.3",
"umzug": "^2.2.0"
},
"devDependencies": {
"@types/graphql": "^14.5.0",
"graphql-tag": "^2.10.1",
"graphql-tools": "^4.0.5",
"jest": "^24.8.0",
"jest-cli": "^24.8.0"
},
"jest": {
"testEnvironment": "node",
"testPathIgnorePatterns": [
"/node_modules/",
"/dist/"
],
typescript
npm
react-apollo
apollo-server
tsconfig
well, it didn't work out for me. installing @types/graphql neither did work "@types/graphql": "14.2.3". Compiler options didn't help "moduleResolution": "node".
Don't know why this is closed.
This what i do, just cast such things as any to workaround the problem
const server = new (ApolloServer as any) ({ typeDefs, resolvers, });
Hello,
Yesterday while I was trying out Apollo for the first time with express and TypeScript, I've stumbled upon the following issue when compiling using TSC:
node_modules/apollo-cache-control/lib/index.d.ts(20,16): error TS2665: Invalid module name in augmentation. Module 'graphql/type/definition' resolves to an untyped module at 'C:/dev/wks/bedeals-mvp/functions/node_modules/graphql/type/definition.js', which cannot be augmented..
At first I filed https://github.com/apollographql/apollo-cache-control/issues/4 but then realized that my imports were causing the issue.
This import causes the issue with TypeScript:
import {graphiqlExpress, graphqlExpress} from "apollo-server-express";
while it works fine with this one:const {graphqlExpress, graphiqlExpress} = require('apollo-server-express');
.You may say "that's the way to import it", but the first import was added for me by IntelliJ's auto-import, which is why I found this to be disturbing. I wasted a lot of time thinking that my node_modules folder wasn't okay, that my TSC version or config was incorrect, ...
It would be nice to have better TypeScript support