2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

既存のNuxtプロジェクトにStorybookをインストールする

Last updated at Posted at 2024-11-05

概要

  • 今のNuxtを採用しているリポジトリにStorybookをインストールときのメモ
  • バージョン
    • nuxt@3.13.2
    • storybook@8.3.2

手順

Nuxt Storybookでいれる

$ npx nuxi@latest module add storybook

packages.json等は勝手に書き換えてくれる

ただ、起動しようとするとエラーがでる

$ yarn run storybook -- --no-open

# ...[ERROR] The entry point "vue" cannot be marked as external

/app/node_modules/@storybook/cli/bin/index.js:23
  throw error;
  ^

Error: Build failed with 1 error:
error: The entry point "vue" cannot be marked as external
    at failureErrorWithLog (/app/node_modules/vite/node_modules/esbuild/lib/main.js:1472:15)
    at /app/node_modules/vite/node_modules/esbuild/lib/main.js:945:25
    at /app/node_modules/vite/node_modules/esbuild/lib/main.js:1353:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errors: [Getter/Setter],
  warnings: [Getter/Setter]
}

Node.js v20.14.0
error Command failed with exit code 7.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

こうする

~/.storybook/main.ts
import type { StorybookConfig } from "@storybook-vue/nuxt";

const config: StorybookConfig = {
  stories: [
    "../stories/**/*.mdx",
    "../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)",
  ],
  addons: [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    "@storybook/addon-interactions",
  ],
  framework: {
    name: "@storybook-vue/nuxt",
    options: {},
  },
  docs: {},
+  viteFinal: (config) => {
+    config.optimizeDeps = {
+      include: ['vue'],
+    };
+    return config;
+  },
};
export default config;

これでおk

他に発生したエラー

Storybookは起動したけど、画面上で表示されたエラー

Failed to fetch dynamically imported module: http://localhost:6006/node_modules/.cache/storybook/1c3385a5d25e538d10b518b310c74d3ca2690b6aaffeadccd74da79736171f86/sb-vite/deps/@storybook_addon-essentials_docs_preview.js?v=2bcf0a9a

  viteFinal: (config) => {
    config.optimizeDeps = {
      include: ['vue', 'jsdoc-type-pratt-parser'],
    };
    return config;
  },

viteFinal 部分に jsdoc-type-pratt-parser を追加した

雑感

まだ何もわかっていない

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?