Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript moduleResolution node16 and nodenext broken #6984

Closed
LinusU opened this issue Oct 3, 2022 · 1 comment
Closed

TypeScript moduleResolution node16 and nodenext broken #6984

LinusU opened this issue Oct 3, 2022 · 1 comment

Comments

@LinusU
Copy link

LinusU commented Oct 3, 2022

I'm getting the following error when using "moduleResolution": "node16" with TypeScript:

node_modules/apollo-server-core/dist/types.d.ts:3:50 - error TS1471: Module '@graphql-tools/schema' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.

3 import type { IExecutableSchemaDefinition } from '@graphql-tools/schema';
                                                   ~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error in node_modules/apollo-server-core/dist/types.d.ts:3

This can be reproduced like so:

index.ts

import { ApolloServer } from 'apollo-server';

const server = new ApolloServer({
  csrfPrevention: true,
  cache: 'bounded',
});
const { url } = await server.listen();
console.log(`🚀 Server ready at ${url}`);

package.json

{
  "type": "module",
  "dependencies": {
    "apollo-server": "^3.10.2",
    "graphql": "^16.6.0"
  },
  "devDependencies": {
    "typescript": "~4.7.4"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "lib": ["ES2021"],
    "module": "ES2022",
    "moduleResolution": "nodenext",
    "target": "ES2021"
  }
}

Then when running tsc:

$ tsc
node_modules/apollo-server-core/dist/types.d.ts:3:50 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("@graphql-tools/schema")' call instead.

3 import type { IExecutableSchemaDefinition } from '@graphql-tools/schema';
                                                   ~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error in node_modules/apollo-server-core/dist/types.d.ts:3

Related reading:

@glasser
Copy link
Member

glasser commented Oct 3, 2022

Good news! Apollo Server 4 (currently a Release Candidate, should be out as v4.0.0 in a week or so) supports ESM modules natively. We even specifically run smoke tests in CI against nodenext. Check out the migration guide.

I would not expect us to make any changes to the build system for Apollo Server 3.

@glasser glasser closed this as completed Oct 3, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants