apollo-server-express、apollo-server 和 apollo-cache-control 中的 TypeScript 导入问题

TypeScript import issues in apollo-server-express, apollo-server & apollo-cache-control

我正在尝试从“apollo-server”更新:“^2.9.4”“apollo-server-express”: "^2.9.4" to 2.12.0 version 在 Typescript 中,在应用程序的构建过程中我得到 以下错误:

node_modules/apollo-server-express/node_modules/apollo-server-core/dist/plugin/index.d.ts:1:13

error TS1005: '=' expected.

1 从 'apollo-server-plugin-base';

导入类型 {ApolloServerPlugin}

我还没有找到解决方法,我已经删除了 node_modules 文件夹和包 -lock.json 但仍然无法正常工作。

能得到一些帮助就好了....

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/"
    ],

您使用的打字稿版本 (v3.6) 不支持 apollo-server-core 中使用的 import type 语法。此语法从 v3.8 开始可用。 https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export

更新打字稿,错误将消失

我在打字稿导入中也遇到了同样的错误,我在 libmodules 和 [=16= 中尝试了不同的值tsconfig.json 文件中的 ]target 但其中 none 有效,我从不想更改 node_modules 文件但最后我不得不(悲伤的笑脸),我在 index.d.ts 文件中所做的更改是
import type { DocumentNode } from 'graphql/language/ast';

import { DocumentNode } from 'graphql/language/ast';
tsconfig.json 中 lib 中的这个值也有帮助
"lib": ["es6", "dom", "esnext", "esnext.asynciterable"],