Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storybook): Fix import issues with storybook vite #10961

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changesets/10961.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- fix(storybook): Fix import issues with storybook vite (#10961) by @Josh-Walker-GM

Fixes an issue with the `yarn rw storybook-vite` command where it would not start due to an import issue.
19 changes: 0 additions & 19 deletions packages/storybook/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { writeFileSync } from 'node:fs'

import { build, defaultBuildOptions } from '@redwoodjs/framework-tools'

await build({
Expand All @@ -9,20 +7,3 @@ await build({
packages: 'external',
},
})

await build({
buildOptions: {
...defaultBuildOptions,
outdir: 'dist/cjs',
format: 'cjs',
packages: 'external',
},
})

// Place a package.json file with `type: commonjs` in the dist folder so that
// all .js files are treated as CommonJS files.
writeFileSync('dist/cjs/package.json', JSON.stringify({ type: 'commonjs' }))

// Place a package.json file with `type: module` in the dist/esm folder so that
// all .js files are treated as ES Module files.
writeFileSync('dist/package.json', JSON.stringify({ type: 'module' }))
10 changes: 3 additions & 7 deletions packages/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,18 @@
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/cjs/index.js",
"import": "./dist/index.js"
"default": "./dist/index.js"
},
"./preset": {
"types": "./dist/preset.d.ts",
"require": "./dist/cjs/preset.js",
"import": "./dist/preset.js"
"default": "./dist/preset.js"
},
"./dist/mocks/MockRouter": {
"require": "./dist/cjs/mocks/MockRouter.js",
"import": "./dist/mocks/MockRouter.js"
"default": "./dist/mocks/MockRouter.js"
},
"./dist/preview.js": "./dist/preview.js",
"./package.json": "./package.json"
},
"main": "dist/cjs/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
Expand Down
1 change: 0 additions & 1 deletion packages/storybook/preset.js

This file was deleted.

10 changes: 10 additions & 0 deletions packages/storybook/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,15 @@ export const viteFinal: StorybookConfig['viteFinal'] = async (config) => {
'~__REDWOOD__USER_WEB_SRC': redwoodProjectPaths.web.src,
},
},
optimizeDeps: {
// Without this, on first run, Vite throws: `The file does not exist at
// "{project path}/web/node_modules/.cache/sb-vite/deps/DocsRenderer-NNNQARDV-DEXCJJZJ.js?v=c640a8fa"
// which is in the optimize deps directory.`
// This refers to @storybook/addon-docs, which is included as part of @storybook/addon-essentials.
// the docs addon then includes itself here: https://github.com/storybookjs/storybook/blob/a496ec48c708eed753a5251d55fa07947a869e62/code/addons/docs/src/preset.ts#L198C3-L198C27
// which I believe gets included by the builder here: https://github.com/storybookjs/storybook/blob/a496ec48c708eed753a5251d55fa07947a869e62/code/builders/builder-vite/src/optimizeDeps.ts#L117
// TODO: Figure out why this error is being thrown so that this can be removed.
exclude: ['@storybook/addon-docs'],
},
})
}
Loading