首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >阿波罗服务器4:生产模式下构建过程中的类型记录错误

阿波罗服务器4:生产模式下构建过程中的类型记录错误
EN

Stack Overflow用户
提问于 2022-10-19 13:50:58
回答 1查看 34关注 0票数 0

我已经将阿波罗服务器从v3迁移到了v4。

它工作一切都很好,但我无法在生产模式下构建该项目,因为@apollo包中有几个类型记录错误。这是剩下的最后两个:

代码语言:javascript
复制
[tsl] ERROR in /home/xxx/projects/dashboard-api/node_modules/@apollo/server/src/ApolloServer.ts(238,53)
      TS2345: Argument of type 'ApolloServerOptions<TContext>' is not assignable to parameter of type 'ApolloServerOptionsWithStaticSchema<TContext>'.
  Type 'ApolloServerOptionsWithGateway<TContext>' is not assignable to type 'ApolloServerOptionsWithStaticSchema<TContext>'.
    Type 'ApolloServerOptionsWithGateway<TContext>' is not assignable to type 'ApolloServerOptionsWithTypeDefs<TContext>'.
      Property 'typeDefs' is optional in type 'ApolloServerOptionsWithGateway<TContext>' but required in type 'ApolloServerOptionsWithTypeDefs<TContext>'.

代码语言:javascript
复制
[tsl] ERROR in /home/xxx/projects/dashboard-api/node_modules/@apollo/server/src/ApolloServer.ts(1140,7)
      TS2322: Type 'string | DocumentNode' is not assignable to type 'string'.
  Type 'DocumentNode' is not assignable to type 'string'.

tsconfig.json

代码语言:javascript
复制
{
    "compilerOptions": {
        "incremental": true,
        "lib": ["ES2020"],
        "target": "ES2020",
        "module": "commonjs",
        "allowJs": false,
        "sourceMap": true,
        "outDir": "./build",
        "strict": true,
        "noImplicitAny": false,
        "strictNullChecks": false,
        "moduleResolution": "node",
        "baseUrl": "./",
        "paths": {
            "@/*": ["src/*"],
            "@/test/*": ["test/*"]
        },
        "esModuleInterop": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true 
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules",
        "./node_modules",
        "./node_modules/*",
        "./node_modules/@types/node/index.d.ts",
    ]
}

webpack.common.js

代码语言:javascript
复制
module.exports = {
    module: {
        rules: [
            {
                test: /\.ts$/,
                exclude: [path.resolve(__dirname, 'node_modules')],
                use: 'ts-loader',
            },
            {
                test: /\.(graphql|gql)$/,
                exclude: /node_modules/,
                loader: 'graphql-tag/loader',
            },
        ],
    },
    output: {
        filename: 'index.js',
        path: path.resolve(__dirname, 'build'),
    },
    resolve: {
        extensions: ['.ts', '.js'],
        alias: {
            '@': path.resolve(__dirname, 'src'),
        },
    },
    target: 'node',
}

webpack.production.js

代码语言:javascript
复制
const common = require('./webpack.common.js')

module.exports = merge(common, {
    devtool: 'source-map',
    entry: [path.join(__dirname, 'src/index.ts')],
    externals: [nodeExternals({})],
    mode: 'production',
    plugins: [new CleanWebpackPlugin()],
})

package.json

代码语言:javascript
复制
{
    "devDependencies": {
        "@types/bcrypt": "^5.0.0",
        "@types/graphql-iso-date": "^3.4.0",
        "@types/jest": "^29.2.0",
        "@types/node": "^14.14.41",
        "@types/pg": "^8.6.5",
        "@types/type-is": "^1.6.3",
        "@types/webpack-env": "^1.18.0",
        "@typescript-eslint/eslint-plugin": "^5.40.1",
        "@typescript-eslint/parser": "^5.40.1",
        "apollo-server-testing": "^2.25.3",
        "aws-sdk-mock": "^5.8.0",
        "clean-webpack-plugin": "^4.0.0",
        "eslint": "^8.25.0",
        "eslint-config-prettier": "^8.5.0",
        "eslint-config-standard": "^17.0.0",
        "eslint-plugin-import": "^2.26.0",
        "eslint-plugin-jest": "^27.1.2",
        "eslint-plugin-prettier": "^4.2.1",
        "eslint-plugin-promise": "^6.1.0",
        "eslint-plugin-standard": "^5.0.0",
        "graphql-tag": "^2.12.6",
        "husky": "^8.0.1",
        "jest": "^29.2.0",
        "jest-mock-extended": "^3.0.1",
        "jest-transform-graphql": "^2.1.0",
        "lint-staged": "^13.0.3",
        "nock": "^13.2.9",
        "nodemon": "^2.0.20",
        "prettier": "^2.7.1",
        "ts-jest": "^29.0.3",
        "ts-loader": "^9.4.1",
        "ts-node": "^10.9.1",
        "tsconfig-paths": "^4.1.0",
        "typescript": "^4.8.4",
        "webpack": "^5.74.0",
        "webpack-cli": "^4.10.0",
        "webpack-merge": "^5.8.0",
        "webpack-node-externals": "^3.0.0"
    },
    "dependencies": {
        "@apollo/datasource-rest": "^4.3.2",
        "@apollo/server": "^4.0.1",
        "@hubspot/api-client": "^7.1.2",
        "@sentry/node": "^7.15.0",
        "@sentry/tracing": "^7.15.0",
        "@shopify/shopify-api": "^5.2.0",
        "@types/cors": "^2.8.12",
        "@types/sanitize-html": "^2.6.2",
        "apollo-datasource-http": "^0.21.0",
        "apollo-server-caching": "^3.3.0",
        "aws-sdk": "^2.1234.0",
        "bcrypt": "^5.1.0",
        "cors": "^2.8.5",
        "date-fns": "^2.29.3",
        "dotenv": "^16.0.3",
        "express": "^4.18.2",
        "graphql": "^16.6.0",
        "graphql-import-node": "0.0.5",
        "graphql-iso-date": "^3.6.1",
        "graphql-tools": "^8.3.6",
        "jsonwebtoken": "^8.5.1",
        "lodash": "^4.17.21",
        "pg": "^8.8.0",
        "sanitize-html": "^2.7.2",
        "yup": "^0.32.11"
    },
    "scripts": {
        "start": "NODE_ENV=development nodemon",
        "build": "NODE_ENV=production webpack --config webpack.production.js",
    }
}

节点版本为v16.16.0

有什么办法可以解决这个问题吗?

EN

回答 1

Stack Overflow用户

发布于 2022-10-20 11:11:52

我已经解决了这两个问题,剩下的就是删除这个导入

代码语言:javascript
复制
import { ExpressContextFunctionArgument } from '@apollo/server/src/express4'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74126579

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档