Skip to content

Commit

Permalink
Add React Peer dep warning
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Dec 13, 2022
1 parent 84dfd4f commit a32abfd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions code/lib/cli/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { sync as readUpSync } from 'read-pkg-up';
import { logger } from '@storybook/node-logger';
import { buildStaticStandalone, withTelemetry } from '@storybook/core-server';
import { cache } from '@storybook/core-common';
import { ensureReactPeerDeps } from './ensure-react-peer-deps';

export const build = async (cliOptions: any) => {
ensureReactPeerDeps();

try {
const options = {
...cliOptions,
Expand Down
3 changes: 3 additions & 0 deletions code/lib/cli/src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { sync as readUpSync } from 'read-pkg-up';
import { logger, instance as npmLog } from '@storybook/node-logger';
import { buildDevStandalone, withTelemetry } from '@storybook/core-server';
import { cache } from '@storybook/core-common';
import { ensureReactPeerDeps } from './ensure-react-peer-deps';

export const dev = async (cliOptions: any) => {
process.env.NODE_ENV = process.env.NODE_ENV || 'development';

ensureReactPeerDeps();

try {
const options = {
...cliOptions,
Expand Down
24 changes: 24 additions & 0 deletions code/lib/cli/src/ensure-react-peer-deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { logger } from '@storybook/node-logger';
import dedent from 'ts-dedent';

export function ensureReactPeerDeps() {
try {
require.resolve('react');
require.resolve('react-dom');
} catch (e) {
logger.error(dedent`
Starting in 7.0, react and react-dom are now required peer dependencies of Storybook.
Please install react and react-dom in your project.
npm:
$ npm add react react-dom --dev
yarn:
$ yarn add react react-dom --dev
pnpm:
$ pnpm add react react-dom --dev
`);
process.exit(1);
}
}

0 comments on commit a32abfd

Please sign in to comment.