Open12

都道府県のやつのメモ

bufferingsbufferings

あとでバージョンかいとこ

❯ node --version
v18.2.0

React 18

Emotion

Storybook

Vite

bufferingsbufferings

Storybook の起動とビルド

Node v17 との組み合わせで ERR_OSSL_EVP_UNSUPPORTED エラーが出る

https://github.com/storybookjs/storybook/issues/16555

NODE_OPTIONS=--openssl-legacy-provider をつけてとりあえず対応

    "storybook": "NODE_OPTIONS=--openssl-legacy-provider start-storybook -p 6006",
    "build-storybook": "NODE_OPTIONS=--openssl-legacy-provider build-storybook"
bufferingsbufferings

Global Decorator

Emotion のテーマを使うのに、Global Decorator を使えばいいのかなと思ってとりあえずサンプルに書いてある通りに preview.js に書きたしてみたらエラーになった

https://storybook.js.org/docs/react/writing-stories/decorators#global-decorators

import React from 'react';

export const decorators = [
  (Story) => (
    <div style={{ margin: '3em' }}>
      <Story />
    </div>
  ),
];
Failed to fetch dynamically imported module: http://localhost:6006/.storybook/preview.js
TypeError: Failed to fetch dynamically imported module: http://localhost:6006/.storybook/preview.js

===

サーバー側のコンソールを見たら Vite がエラーメッセージを出してた

12:21:30 AM [vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.

拡張子ちゃんとしてよってことか。preview.jsx にリネームしてみたら動いた。わーい。

↓は必要なさそうなので消しておいた

import React from 'react';
bufferingsbufferings

ThemeProvider

Decorator で ThemeProvider を指定してみる

import { theme } from '../src/themes/theme';
import { ThemeProvider } from '@emotion/react';

export const decorators = [
  (Story) => (
    <ThemeProvider theme={theme}>
      <Story />
    </ThemeProvider>
  ),
];

動いた

bufferingsbufferings

インポート

次はインポートの ../src/src/ で動くようにしたい。何もしなかったら見つけられないエラーになる。

12:36:59 AM [vite] Internal server error: Failed to resolve import "src/themes/theme" from ".storybook/preview.jsx". Does the file exist?

==

このあたり読みながらやってみようー

https://storybook.js.org/docs/react/builders/webpack#typescript-module-resolution

https://zenn.dev/link/comments/5664866beee140

https://zenn.dev/longbridge/articles/13e65ef71455e4

bufferingsbufferings

これでいけた

main.js

const path = require('path');

module.exports = {
  ...
  viteFinal: async (config) => {
    config.resolve.alias = {
      ...(config.resolve.alias || {}),
      src: path.resolve(__dirname, '../src'),
    };
    return config;
  },
};

bufferingsbufferings

でも、一回目はエラーになるのなんだろうなぁ?一回起動してエラーになって、再起動したらいける。キャッシュ周りのなにかなのかなぁ?