Skip to content

Commit 48b7472

Browse files
authored
fix(storybook): Adding vite-plugin-node-polyfills to SB Vite config (#12050)
Our vite package already depends on vite-plugin-node-polyfills, but yarn would sometimes place that package inside node_modules inside the vite package instead of at the root node_modules. So when it was requested by Storybook's vite node wouldn't find it. Explicitly adding it to Storybook and its vite config solves this. Fix first discovered and merged here: cedarjs/cedar#2
1 parent ca01891 commit 48b7472

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

packages/storybook/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
"@storybook/react": "7.6.20",
5757
"magic-string": "0.30.11",
5858
"react-docgen": "7.0.3",
59-
"unplugin-auto-import": "0.18.3"
59+
"unplugin-auto-import": "0.18.3",
60+
"vite-plugin-node-polyfills": "0.23.0"
6061
},
6162
"devDependencies": {
6263
"@types/node": "20.17.10",

packages/storybook/src/preset.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { dirname, join } from 'path'
1+
import path from 'node:path'
22

33
import type { PresetProperty } from '@storybook/types'
44
import { mergeConfig } from 'vite'
5+
import { nodePolyfills } from 'vite-plugin-node-polyfills'
56

67
import { getPaths } from '@redwoodjs/project-config'
78

@@ -12,7 +13,7 @@ import { reactDocgen } from './plugins/react-docgen'
1213
import type { StorybookConfig } from './types'
1314

1415
const getAbsolutePath = (input: string) =>
15-
dirname(require.resolve(join(input, 'package.json')))
16+
path.dirname(require.resolve(path.join(input, 'package.json')))
1617

1718
export const core: PresetProperty<'core'> = {
1819
builder: getAbsolutePath('@storybook/builder-vite'),
@@ -32,6 +33,7 @@ export const viteFinal: StorybookConfig['viteFinal'] = async (config) => {
3233

3334
// Needs to run before the react plugin, so add to the front
3435
plugins.unshift(reactDocgen())
36+
plugins.unshift(nodePolyfills())
3537

3638
return mergeConfig(config, {
3739
// This is necessary as it otherwise just points to the `web` directory,

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27790,6 +27790,7 @@ __metadata:
2779027790
typescript: "npm:5.6.2"
2779127791
unplugin-auto-import: "npm:0.18.3"
2779227792
vite: "npm:5.4.16"
27793+
vite-plugin-node-polyfills: "npm:0.23.0"
2779327794
peerDependencies:
2779427795
"@redwoodjs/project-config": "workspace:*"
2779527796
"@redwoodjs/router": "workspace:*"

0 commit comments

Comments
 (0)