[英]TypeScript import issues in apollo-server-express, apollo-server & apollo-cache-control
I'm trying to update from " apollo-server": "^2.9.4" and "apollo-server-express" : "^2.9.4" to 2.12.0 version in Typescript, During the build process of the app I get the following error:我正在尝试在 Typescript 中从“ apollo-server”:“^2.9.4”和“apollo-server-express” :“^2.9.4”更新到2.12.0 版本,在应用程序的构建过程中,我得到以下错误:
node_modules/apollo-server-express/node_modules/apollo-server-core/dist/plugin/index.d.ts:1:13
node_modules/apollo-server-express/node_modules/apollo-server-core/dist/plugin/index.d.ts:1:13
error TS1005: '=' expected.
错误 TS1005: '=' 预期。
1 import type { ApolloServerPlugin } from 'apollo-server-plugin-base'; 1 从“apollo-server-plugin-base”导入类型 { ApolloServerPlugin };
I have not found the fix for this yet, I've deleted node_modules folder and package-lock.json but still not working.我还没有找到解决这个问题的方法,我已经删除了 node_modules 文件夹和 package-lock.json 但仍然无法正常工作。
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/"
],
The import type
syntax used in apollo-server-core isn't supported by the version of typescript that you're using (v3.6).您使用的打字稿版本 (v3.6) 不支持 apollo-server-core 中使用的
import type
语法。 This syntax became available from v3.8 onwards.此语法从 v3.8 开始可用。 https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export
Update typescript and the error will disappear更新打字稿,错误将消失
I was also facing same kind of error in typescript imports, I tried different values in lib , modules and target in tsconfig.json file but none of them worked, I never wanted to change the node_modules file but in the end I had to (sad smiley), change I made in my index.d.ts
file was我在打字稿导入时也遇到了同样的错误,我在 tsconfig.json 文件中的lib 、 modules和target中尝试了不同的值,但它们都不起作用,我从不想更改node_modules文件,但最后我不得不(悲伤笑脸),我在
index.d.ts
文件中所做的更改是import type { DocumentNode } from 'graphql/language/ast';
to到
import { DocumentNode } from 'graphql/language/ast';
also this value in lib in tsconfig.json also helped tsconfig.json 中 lib 中的这个值也有帮助
"lib": ["es6", "dom", "esnext", "esnext.asynciterable"],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.