Skip to content

Commit

Permalink
Add error message for Next.js if swc is not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Nov 20, 2023
1 parent 3fb18f1 commit a52d9ef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
11 changes: 2 additions & 9 deletions code/frameworks/nextjs/src/swc/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import type { NextConfig } from 'next';
import path from 'path';
import type { RuleSetRule } from 'webpack';
import semver from 'semver';
import { dedent } from 'ts-dedent';
import { logger } from '@storybook/node-logger';
import { NextjsSWCNotSupportedError } from 'lib/core-events/src/errors/server-errors';
import { getNextjsVersion } from '../utils';

export const configureSWCLoader = async (
Expand All @@ -19,13 +18,7 @@ export const configureSWCLoader = async (
const version = getNextjsVersion();

if (semver.lt(version, '14.0.0')) {
logger.warn(
dedent`You have activated the SWC mode for Next.js, but you are not using Next.js 14.0.0 or higher.
SWC is only supported in Next.js 14.0.0 and higher.
Skipping SWC and using Babel instead.
`
);
return;
throw new NextjsSWCNotSupportedError();
}

const dir = getProjectRoot();
Expand Down
17 changes: 17 additions & 0 deletions code/lib/core-events/src/errors/server-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,20 @@ export class GoogleFontsLoadingError extends StorybookError {
`;
}
}

export class NextjsSWCNotSupportedError extends StorybookError {
readonly category = Category.FRAMEWORK_NEXTJS;

readonly code = 3;

public readonly documentation =
'https://github.com/storybookjs/storybook/blob/next/code/frameworks/nextjs/README.md#manual-migration';

template() {
return dedent`
You have activated the SWC mode for Next.js, but you are not using Next.js 14.0.0 or higher.
SWC is only supported in Next.js 14.0.0 and higher. Please go to your .storybook/main.<js|ts> file
and remove the { framework: { options: { builder: { useSWC: true } } } } option or upgrade to Next.js v14 or later.
`;
}
}

0 comments on commit a52d9ef

Please sign in to comment.