Skip to content

Commit f9fa9fb

Browse files
authored
Fix storybook build errors and warnings (#13389)
There are two groups of issues with the Storybook build: 1. A "Module not found" warning related to the "os" node module. 2. A pair of "ENOTDIR" errors related to `bridgetApi.ts` and `logging.ts`. The first is caused by `clean-css`, which attempts to import the "os" module that's built into Node.js. Storybook's Webpack is building for the browser so this module is not available, and it's not automatically polyfilled as of Webpack 5. The "os" module is not required for our usage of `clean-css`, so the solution is to instruct Webpack to provide an empty module via `resolve.fallback`. The second issue is caused by our attempt to mock the `logging.ts` and `bridgetApi.ts` modules in Storybook. Webpack is attempting to treat these as directories during the compilation process, which causes the above error. Removing the `.ts` file extensions solves this. This change also adds a `$` suffix to these paths, which makes sure an exact match is always used.
1 parent 7d6fa8e commit f9fa9fb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

dotcom-rendering/.storybook/main.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const config: StorybookConfig = {
5151
// clean-css will try to import these packages
5252
config.resolve.fallback['http'] = false;
5353
config.resolve.fallback['https'] = false;
54+
config.resolve.fallback['os'] = false;
5455

5556
// Required as otherwise 'process' will not be defined when included on its own (without .env)
5657
// e.g process?.env?.SOME_VAR
@@ -103,12 +104,13 @@ const webpackConfig = (config: Configuration) => {
103104

104105
// log4js tries to call "fs" in storybook -- we can ignore it
105106
config.resolve.alias[
106-
path.resolve(__dirname, '../src/server/lib/logging.ts')
107+
`${path.resolve(__dirname, '../src/server/lib/logging')}$`
107108
] = path.resolve(__dirname, './mocks/log4js.ts');
108109

109110
// Mock BridgetApi for storybook
110-
config.resolve.alias[path.resolve(__dirname, '../src/lib/bridgetApi.ts')] =
111-
path.resolve(__dirname, './mocks/bridgetApi.ts');
111+
config.resolve.alias[
112+
`${path.resolve(__dirname, '../src/lib/bridgetApi')}$`
113+
] = path.resolve(__dirname, './mocks/bridgetApi.ts');
112114

113115
const webpackLoaders = getLoaders('client.web');
114116

0 commit comments

Comments
 (0)