Skip to content

Commit

Permalink
fix: resolve module not found error '@storybook/builder-vite' (#724)
Browse files Browse the repository at this point in the history
<!---
☝️ PR title should follow conventional commits
(https://conventionalcommits.org)
-->

### 🔗 Linked issue

Fixes #720.


<!-- If it resolves an open issue, please link the issue here. For
example "Resolves #123" -->

### ❓ Type of change

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply. -->

- [ ] 📖 Documentation (updates to the documentation or readme)
- [ ] 🐞 Bug fix (a non-breaking change that fixes an issue)
- [ ] 👌 Enhancement (improving an existing functionality)
- [ ] ✨ New feature (a non-breaking change that adds functionality)
- [ ] 🧹 Chore (updates to the build process or auxiliary tools and
libraries)
- [ ] ⚠️ Breaking change (fix or feature that would cause existing
functionality to change)

### 📚 Description

<!-- Describe your changes in detail -->
<!-- Why is this change required? What problem does it solve? -->
  • Loading branch information
tobiasdiez authored Jul 18, 2024
1 parent 49e7a39 commit 0d04e00
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions packages/storybook-addon/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ export const core: PresetProperty<'core', StorybookConfig> = async (
) => {
return {
...config,
builder: '@storybook/builder-vite',
renderer: '@storybook/vue3',
builder: await getPackageDir('@storybook/builder-vite'),
renderer: await getPackageDir('@storybook/vue3'),
}
}
/**
Expand All @@ -230,7 +230,6 @@ export const viteFinal: StorybookConfig['viteFinal'] = async (
) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const getStorybookViteConfig = async (c: Record<string, any>, o: any) => {
// const pkgPath = await getPackageDir('@storybook/vue3-vite')
const presetURL = pathToFileURL(
join(await getPackageDir('@storybook/vue3-vite'), 'preset.js'),
)
Expand Down Expand Up @@ -265,21 +264,17 @@ export const viteFinal: StorybookConfig['viteFinal'] = async (
}

async function getPackageDir(frameworkPackageName: string) {
// const packageJsonPath = join(frameworkPackageName, 'package.json')

try {
const require = createRequire(import.meta.url)
const packageDir = dirname(
require.resolve(join(frameworkPackageName, 'package.json'), {
paths: [process.cwd()],
}),
)

return packageDir
} catch (e) {
// logger.error(e)
throw new Error(`Cannot find ${frameworkPackageName}`, { cause: e })
}
throw new Error(`Cannot find ${frameworkPackageName},`)
}

export function getNuxtProxyConfig(nuxt: Nuxt) {
Expand Down

0 comments on commit 0d04e00

Please sign in to comment.