Monorepo Shared Config #25730
Replies: 2 comments
-
I encountered the same issue. Interestingly, you can import shared config with a relative file path (e.g., While not ideal, using a relative path can be a workaround in a monorepo setup. I searched for similar bug reports in issues. #21701 seems to be related to this issue. |
Beta Was this translation helpful? Give feedback.
-
Have the same problem with storybook 8.3.4 import { createDefaultStorybookMainConfig } from '@test-utils/storybook/config/main'
const storybookConfig = createDefaultStorybookMainConfig({
stories: ['../stories/**/*.mdx', '../stories/**/*.stories.@(ts|tsx)'],
staticDirs: [],
}, {
module: {
rules: [
{
test: /\.module\.(s)?css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
},
},
'sass-loader',
],
},
{
test: /\.scss$/,
exclude: /\.module.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.(woff(2)?|eot|ttf|otf|)$/,
type: 'asset',
},
]
}
});
export default storybookConfig; Where import path from 'path';
import { merge } from 'webpack-merge';
import type { StorybookConfig } from '@storybook/react-webpack5';
import { getLocalIdentName } from 'css-loader-shorter-classnames';
import type { Configuration} from 'webpack'
const getLocalIdent = getLocalIdentName();
/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
const getAbsolutePath = (value: string) => path.dirname(require.resolve(path.join(value, 'package.json')));
export const createDefaultStorybookMainConfig: (storybookConfig: Partial<StorybookConfig>, webpackConfig?: Configuration) => StorybookConfig = (storybookConfig, webpackConfig) => ({
stories: ['../tests/**/stories/**/*.stories.@(ts|tsx)'],
addons: [
getAbsolutePath('@storybook/addon-webpack5-compiler-swc'),
getAbsolutePath('@storybook/addon-onboarding'),
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@chromatic-com/storybook'),
getAbsolutePath('@storybook/addon-interactions'),
{
name: 'storybook-css-modules',
options: {
cssModulesLoaderOptions: {
importLoaders: 1,
modules: {
getLocalIdent,
},
},
},
},
],
framework: {
name: getAbsolutePath('@storybook/react-webpack5'),
options: {},
},
webpackFinal: async (config: Configuration) => {
if (webpackConfig) {
return merge(config, webpackConfig);
}
return config;
},
...storybookConfig,
}); Storybook runs, works well, but mine console is fullfiled of an error
This clogs up the console a lot. |
Beta Was this translation helpful? Give feedback.
-
I have a monorepo with many features (projects / modules) which each have storybook stories. We run an independent Storybook instance in each of the features and then deploy it to an internal site for non-dev's to interact with.
Right now our
.storybook/main.ts
file looks like:But it leads to a mess of errors (which are more annoying than anything):
Is there any way to avoid these errors?
I get that Storybook is trying to use static analysis to load (at the very least) the story sorting algorithm. But it would be nice to be able to have shared configuration + a story sorting algorithm.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions