You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用NestJS、Prisma及GraphQL运行npm run start:dev时遭遇Missing 'driver' option错误的解决咨询

Fixing "Missing 'driver' option" Error in NestJS GraphQL v10

Hey there! That error you're hitting is because NestJS GraphQL v10 introduced a breaking change—the driver configuration option is now required, since the module no longer defaults to Apollo Server under the hood. Let's walk through how to fix this step by step.

Step 1: Install Required Dependencies

First, make sure you have the Apollo driver package installed (since you're using Apollo's landing page plugin, we'll stick with Apollo):

npm install @nestjs/apollo @apollo/server graphql

Step 2: Update Your app.module.ts

You need to import the ApolloDriver and ApolloDriverConfig from @nestjs/apollo, then add the mandatory driver property to your GraphQLModule.forRoot configuration. Here's the full corrected code:

import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
// Add these Apollo-specific imports
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default';
import { DonationsModule } from './donations/donations.module';

@Module({
  imports: [
    GraphQLModule.forRoot<ApolloDriverConfig>({
      // Required driver property to specify Apollo as the GraphQL server
      driver: ApolloDriver,
      // Keep your existing plugin and type path settings
      plugins: [ApolloServerPluginLandingPageLocalDefault()],
      typePaths: ['./**/*.graphql'],
      // Keep playground disabled since you're using Apollo's landing page
      playground: false,
    }),
    DonationsModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Key Changes Explained:

  • Added imports for ApolloDriver and ApolloDriverConfig to enable Apollo Server integration
  • Added the driver: ApolloDriver property (the missing required config)
  • Used ApolloDriverConfig as the generic type for forRoot to get proper TypeScript type checking
  • Updated the import path for the Apollo landing page plugin (it moved in newer Apollo Server versions)

Step 3: Verify Your generate-typings.ts

Your existing generate-typings.ts should work as-is with the updated setup, since it only generates TypeScript types from your .graphql files. If you run into issues here, double-check that all your GraphQL dependencies are on compatible versions (v10 of @nestjs/graphql pairs seamlessly with the latest @nestjs/apollo).

Test the Fix

Now fire up your dev server again:

npm run start:dev

The "Missing 'driver' option" error should be resolved, and your GraphQL server should start up with the Apollo landing page accessible at your server's GraphQL endpoint.

内容的提问来源于stack exchange,提问作者yuturo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 13:34:07