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

Use with Vite builder #2

Closed
brettdewoody opened this issue Oct 25, 2021 · 8 comments
Closed

Use with Vite builder #2

brettdewoody opened this issue Oct 25, 2021 · 8 comments

Comments

@brettdewoody
Copy link

I'm using Vite (instead of webpack) and when implementing storybook-react-i18next there's an error of:

Uncaught ReferenceError: require is not defined
    at preview.js?

due to this file using a require statement.

Any desire to make this work with Vite? If so I'd like to take a shot at a PR.

@stevensacks
Copy link
Owner

I actually didn't write that part (Shilman did) so I'm not sure how to change it. If you know how to change it and have it work universally, by all means, please submit a PR 😊

@shilman
Copy link

shilman commented Jan 28, 2022

There are two proposed fixes to a similar problem here:

The first renames the file to .cjs. The second switches to async imports, which I don't think applies here (including for completeness). That might be enough to solve the issue?

@MarkLyck
Copy link

MarkLyck commented Mar 3, 2022

@stevensacks @brettdewoody I just stumbled upon this, after running into the same error.

Did you ever find a solution? and if it's not part of this code that needs fixing, which github repo should I be looking at?

I see that 1 of the 2 PRs above was merged, and the other was closed? But at least in the latest storybook it's still broken.

I tried @next, and got this error instead:

Uncaught SyntaxError: The requested module '/node_modules/@storybook/addon-docs/node_modules/acorn-jsx/index.js?v=ae9ccf26' does not provide an export named 'default'

But that seems unrelated and happens whether storybook-react-i18next is there or not.

For now I've had to completely remove this addon from storybook to keep developing.

@wanbinkimoon
Copy link

same problem here

@laneschmidt
Copy link

same issue: #11

this issue could also be related, i'm pretty ignorant on ES modules vs CommonJS though.

@dohomi
Copy link

dohomi commented May 16, 2022

I can confirm, a basic starter with storybook-vite breaks after installing this plugin with the require statement. I use React 17 not 18 as mentioned in #11

@thomasverleye
Copy link

Hi everyone 👋

I've fixed this by using a Backend (the same I'm using for our Remix-i18next setup 🤗) instead of loading all locale json files.

Here you can see my .storybook/i18next.js config file:

import {initReactI18next} from 'react-i18next';
import i18n from 'i18next';
import Backend from 'i18next-http-backend';

const ns = ['common'];
const supportedLngs = ['en'];

i18n.use(initReactI18next)
    .use(Backend)
    .init({
        //debug: true,
        lng: 'en',
        fallbackLng: 'en',
        interpolation: {
            escapeValue: false,
        },
        react: { useSuspense: false },
        defaultNS: 'common',
        ns,
        supportedLngs,
        backend: {
          loadPath: '/locales/{{lng}}/{{ns}}.json'
        }
    });

export default i18n;

As you can see I use i18next-http-backend as my backend and added a loadPath instead of requiring all files once :-)
The files don't have relative paths as my public folder is set to a static dir in Storybook ;-)

I have also added react: { useSuspense: false }, to the config because when reloading a component in browser I'm getting suspense errors in Storybook.

Have a nice day 👋

@stevensacks
Copy link
Owner

Storybook 7 and version 2 of this add-on should work with Vite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants