Skip to content

Commit

Permalink
fix(nextjs): Improve NextConfigExports compatibility
Browse files Browse the repository at this point in the history
Passing type `import('next/dist/next-server/server/config').NextConfig` into `withSentryConfig` results in a type-checking error (`ts(2345)`):

```
Argument of type 'NextConfig' is not assignable to parameter of type 'NextConfigExports'.
  Types of property 'experimental' are incompatible.
    Type '{ cpus?: number; plugins?: boolean; profiling?: boolean; sprFlushToDisk?: boolean; reactMode?: "legacy" | "concurrent" | "blocking"; workerThreads?: boolean; pageEnv?: boolean; optimizeImages?: boolean; ... 13 more ...; gzipSize?: boolean; }' is not assignable to type '{ plugins: boolean; }'.
      Property 'plugins' is optional in type '{ cpus?: number; plugins?: boolean; profiling?: boolean; sprFlushToDisk?: boolean; reactMode?: "legacy" | "concurrent" | "blocking"; workerThreads?: boolean; pageEnv?: boolean; optimizeImages?: boolean; ... 13 more ...; gzipSize?: boolean; }' but required in type '{ plugins: boolean; }'.
```
  • Loading branch information
meeq authored and kamilogorek committed Jun 10, 2021
1 parent 925c114 commit 888c14a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/nextjs/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { dropUndefinedKeys, logger } from '@sentry/utils';
import defaultWebpackPlugin, { SentryCliPluginOptions } from '@sentry/webpack-plugin';
import * as SentryWebpackPlugin from '@sentry/webpack-plugin';
import * as fs from 'fs';
import { NextConfig } from 'next/dist/next-server/server/config';
import * as path from 'path';

const SENTRY_CLIENT_CONFIG_FILE = './sentry.client.config.js';
Expand Down Expand Up @@ -110,9 +111,7 @@ const injectSentry = async (origEntryProperty: EntryProperty, isServer: boolean)
return newEntryProperty;
};

type NextConfigExports = {
experimental?: { plugins: boolean };
plugins?: string[];
type NextConfigExports = Partial<NextConfig> & {
productionBrowserSourceMaps?: boolean;
webpack?: WebpackExport;
};
Expand All @@ -125,7 +124,7 @@ type NextConfigExports = {
* @returns The modified config to be exported
*/
export function withSentryConfig(
providedExports: NextConfigExports = {},
providedExports: Partial<NextConfig> = {},
providedSentryWebpackPluginOptions: Partial<SentryCliPluginOptions> = {},
): NextConfigExports {
const defaultSentryWebpackPluginOptions = dropUndefinedKeys({
Expand Down

0 comments on commit 888c14a

Please sign in to comment.