错误 TS2416:“ApolloError”类型中的属性“originalError”不可分配给基类型“GraphQLError”中的相同属性
Posted
技术标签:
【中文标题】错误 TS2416:“ApolloError”类型中的属性“originalError”不可分配给基类型“GraphQLError”中的相同属性【英文标题】:error TS2416: Property 'originalError' in type 'ApolloError' is not assignable to the same property in base type 'GraphQLError' 【发布时间】:2021-12-12 20:50:33 【问题描述】:版本
阿波罗服务器错误:3.2.0
graphql:15.6.1/15.7.0
nestjs-cli: 8.1.2
npm:6.14.15
打字稿:4.4.4
错误:
node_modules/apollo-server-errors/dist/index.d.ts:10:5 - error TS2416: Property 'originalError' in type 'ApolloError' is not assignable to the same property in base type 'GraphQLError'.
Type 'Error | null | undefined' is not assignable to type 'Error | undefined'.
Type 'null' is not assignable to type 'Error | undefined'.
10 originalError: Error | null | undefined;
在我错误地清除了我的 node_modules 并使用此 package.json 文件构建后,此问题开始出现:
"name": "priojet-backend",
"version": "0.13.6",
"description": "The PRIOjet backend providing APIs (GraphQL and REST) and managing the data stored in a Postgres database.",
"author": "Tobias Wolff, Shivam Pathak",
"private": true,
"license": "UNLICENSED",
"type": "commonjs",
"scripts":
"prebuild": "rimraf dist",
"build": "NODE_ENV=production nest build -p tsconfig.build.json",
"build:docker": "NODE_ENV=docker nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "NODE_ENV=development nest start",
"start:dev": "NODE_ENV=development nest start --watch",
"start:dev:windows": "set NODE_ENV=development && nest start --watch",
"start:debug": "NODE_ENV=development npm-run-all create-api-info-files && NODE_ENV=development nest start --debug --watch",
"start:debug:docker": "NODE_ENV=docker nest start --debug --watch",
"start:prod": "NODE_ENV=production node dist/main",
"start:prod:pm2": "NODE_ENV=production pm2 start dist/main.js -i 0",
"start:devprod": "NODE_ENV=production DEVPROD=1 ts-node ./migrate.ts && node dist/main",
"lint": "eslint \"src,apps,libs,test/**/*.ts\" --fix",
"test": "NODE_ENV=test TS_JEST=1 jest --detectOpenHandles --maxWorkers=50%",
"test:vscode-jest": "NODE_ENV=test TS_JEST=1 jest \"--detectOpenHandles\" \"--maxWorkers=50%\"",
"test:watch": "NODE_ENV=test TS_JEST=1 jest --detectOpenHandles --runInBand --watch --no-cache --silent=false",
"test:cov": "NODE_ENV=test TS_JEST=1 jest --detectOpenHandles --runInBand --coverage",
"test:cov:docker": "NODE_ENV=docker TS_JEST=1 jest --detectOpenHandles --coverage",
"test:debug": "NODE_ENV=test TS_JEST=1 node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "NODE_ENV=test TS_JEST=1 jest --config ./test/jest-e2e.json",
"test:changes": "NODE_ENV=test TS_JEST=1 jest -o",
"todo": "grep -R --exclude-dir=node_modules 'todo' .",
"TODO": "grep -R --exclude-dir=node_modules 'TODO' .",
"loose-types": "echo -e 'anys:\n\n'; grep -r any src; echo -e '\n\nfunctions\n\n'; grep -r function src; echo -e '\n\n';",
"db": "npx mikro-orm",
"db:help": "cat ./src/migrations/cli.ts",
"db:update": "ts-node ./migrate.ts",
"db:init": "npx mikro-orm schema:create -r",
"db:migration:create": "npx mikro-orm migration:create",
"db:migration:up": "npx mikro-orm migration:up # Migrate up to the latest version",
"db:migration:down": "npx mikro-orm migration:down # Migrate one step down",
"db:migration:list": "npx mikro-orm migration:list # List all executed migrations",
"db:migration:pending": "npx mikro-orm migration:pending # List all pending migrations",
"prebuild:prod": "rimraf dist # && tsc",
"create-api-info-files": "./create_api_info_files.sh"
,
"dependencies":
"@apollo/federation": "^0.33.0",
"@apollo/gateway": "^0.33.0",
"@azure/identity": "^1.5.0",
"@azure/storage-blob": "^12.6.0",
"@casl/ability": "^5.3.1",
"@fingerprintjs/fingerprintjs": "^3.2.0",
"@googlemaps/google-maps-services-js": "^3.2.5",
"@mikro-orm/cli": "^4.5.9",
"@mikro-orm/core": "^4.5.9",
"@mikro-orm/knex": "^4.5.9",
"@mikro-orm/migrations": "^4.5.9",
"@mikro-orm/nestjs": "^4.3.0",
"@mikro-orm/postgresql": "^4.5.9",
"@mikro-orm/reflection": "^4.5.9",
"@nestjs/axios": "^0.0.2",
"@nestjs/common": "^8.0.0",
"@nestjs/config": "^1.0.2",
"@nestjs/core": "^8.0.0",
"@nestjs/event-emitter": "^1.0.0",
"@nestjs/graphql": "^9.0.6",
"@nestjs/passport": "^8.0.0",
"@nestjs/platform-express": "^8.0.11",
"@sentry/node": "^6.13.2",
"@sentry/tracing": "^6.13.2",
"@types/jest": "^27.0.1",
"@types/lodash": "^4.14.175",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0",
"apollo-server-core": "^3.4.0",
"apollo-server-errors": "^3.2.0",
"apollo-server-express": "^3.4.0",
"apollo-server-types": "^3.3.0",
"axios": "^0.21.4",
"axios-retry": "^3.2.0",
"azure-storage": "^2.10.4",
"body-parser": "^1.19.0",
"bx24-api": "^1.4.1",
"check-peer-dependencies": "^4.0.0",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"cluster": "^0.7.7",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"expo-device": "^3.1.1",
"express": "^4.17.1",
"form-data": "^4.0.0",
"graphql": "^15.6.1",
"graphql-type-json": "^0.3.2",
"http": "^0.0.1-security",
"http-proxy-middleware": "^2.0.1",
"nest-raven": "^8.0.0",
"passport": "^0.4.1",
"passport-azure-ad": "^4.3.1",
"passport-jwt": "^4.0.0",
"randomstring": "^1.2.1",
"reflect-metadata": "^0.1.13",
"request-ip": "^2.1.3",
"sharp": "^0.29.1",
"ts-morph": "^12.0.0",
"ts-node": "^10.2.1",
"tsconfig-paths": "^3.9.0",
"tsutils": "^3.21.0",
"typescript": "^4.4.2",
"util": "^0.12.4",
"uuid": "^8.3.2",
"webpack": "^5.58.1"
,
"devDependencies":
"@compodoc/compodoc": "^1.1.15",
"@nestjs/cli": "^8.1.2",
"@nestjs/schematics": "^8.0.3",
"@nestjs/testing": "^8.0.11",
"@types/express": "^4.17.13",
"@types/jest": "^27.0.2",
"@types/multer": "^1.4.7",
"@types/node": "^16.10.2",
"@types/node-fetch": "^3.0.3",
"@types/request-ip": "0.0.37",
"@types/supertest": "^2.0.10",
"autoclean": "^1.0.2",
"eslint": "7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.2",
"faker": "^5.4.0",
"jest": "^27.2.4",
"jest-junit": "^13.0.0",
"npm-run-all": "^4.1.5",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"supertest": "^6.1.3",
"ts-jest": "27.0.5",
"ts-loader": "^9.2.6",
"ts-node": "^10.3.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.4.4"
,
"jest":
"testTimeout": 60000,
"moduleFileExtensions": [
"json",
"ts",
"js"
],
"globalSetup": "./jest-setup.ts",
"globalTeardown": "./jest-teardown.ts",
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform":
"^.+\\.(ts|tsx)$": "ts-jest"
,
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node",
"reporters": [
"default",
"jest-junit"
],
"coverageThreshold":
"global":
"branches": 40,
"functions": 45,
"lines": 75,
"statements": 75
,
"modulePathIgnorePatterns": [
"dist/package.json",
"<rootDir>/package.json"
]
,
"jest-junit":
"suiteName": "jest tests",
"outputDirectory": "test_results",
"outputName": "junit.xml",
"uniqueOutputName": "false",
"classNameTemplate": "classname-title",
"titleTemplate": "classname-title",
"ancestorSeparator": " › ",
"usePathForSuiteName": "true"
,
"mikro-orm":
"useTsNode": true,
"tsConfigPath": "tsconfig.json",
"configPaths": [
"dist/config/database/postgres/mikro-orm.config.js",
"src/config/database/postgres/mikro-orm.config.ts"
],
"entities": [
"dist/entities/*.entity.js"
],
"entitiesTs": [
"src/entities/*.entity.ts"
]
我的配置可能出了什么问题?如果它与 apollo-server 上的最新更新有关,我什么时候可以期待解决方案?这是一个阻止程序,因为我的应用程序无法运行。
【问题讨论】:
【参考方案1】:请注意,这已在 graphql.js 15.7.1 中修复:
https://github.com/graphql/graphql-js/pull/3341
【讨论】:
【参考方案2】:降级到 graphql 也对我有用。另外,我尝试使用补丁包作为解决方法,只是为了不被阻止。 https://www.npmjs.com/package/patch-package
【讨论】:
降级到哪个版本?为什么这个链接?请edit您的回答以添加更多详细信息 降级到 15.3.0。 patch-package 只是解决问题的一种解决方法。它允许您调整依赖项中的代码,为 node_modules 创建一个虚拟包。不推荐,但我将其用于本地试用。无论如何,graphql 已经在 15.7.1 版本中解决了这个问题。我更新了它,一切正常。【参考方案3】:显然,GraphQLError.originalError
的类型在某个时候从 originalError?: Maybe<Error>
更改为 Error | undefined
。降级到 graphql 15.3.0 为我解决了这个问题。
【讨论】:
以上是关于错误 TS2416:“ApolloError”类型中的属性“originalError”不可分配给基类型“GraphQLError”中的相同属性的主要内容,如果未能解决你的问题,请参考以下文章
TS2416:“MyGuard”类型中的属性“canActivate”不可分配给基类型“CanActivate”中的相同属性
TS/SFC/RenderProp:无法调用类型缺少调用签名的表达式
ApolloError.js:43 Uncaught (in promise) 错误:网络错误:无法读取未定义的属性“突变”
React Native:无法在“FormData”上执行“附加”:参数 2 不是“Blob”类型。在新的 ApolloError