-
-
Notifications
You must be signed in to change notification settings - Fork 764
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
Add storybook example #1012
Comments
I had the same issue and I fixed it by adding some webpack magic to the storybook setup: // .storybook/main.js
module.exports = {
addons: [
...
],
stories: [
...
],
webpackFinal: (config) => {
return {
...config,
node: {
...config.node,
fs: 'empty',
},
}
},
} I hope this works for you! |
Yeah, adding |
FTR: if you have issues with First of all, add this to your // .storybook/main.js
module.exports = {
/**
* Storybook uses Webpack@4 by default, but we require Webpack@5 already.
* @see https://storybook.js.org/blog/storybook-for-webpack-5/
* @see https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324#upgrade
*/
core: {
builder: 'webpack5',
},
// ... other settings
webpackFinal: config => {
/**
* Fixes issue with `next-i18next` and is ready for webpack@5
* @see https://github.com/isaachinman/next-i18next/issues/1012#issuecomment-792697008
* @see https://github.com/storybookjs/storybook/issues/4082#issuecomment-758272734
* @see https://webpack.js.org/migrate/5/
*/
config.resolve.fallback = {
fs: false,
tls: false,
net: false,
module: false,
path: require.resolve('path-browserify'),
}
return config
},
} But that's not enough! You also need to adjust the decorators. // .storybook/preview.js
import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
export const decorators = [
// ... other decorators
(Story, Context) => {
i18n.use(initReactI18next).init({
lng: 'en',
fallbackLng: 'en',
// have a common namespace used around the full app
ns: ['translations'],
defaultNS: 'translations',
// debug: true,
interpolation: {
escapeValue: false, // not needed for react!!
},
// TODO: load actual translations from the *.json files
resources: { en: { translations: {} } },
})
return <Story />
},
] @isaachinman, I support @magnattic's initial request that this repo should contain a storybook example. It could help others to resolve the issue quickly without getting frustrated. Please, think about it. Thanks. Edit: This could be of interest to others as well: Using next-i18next in Storybook. I have not tried it yet, but it looks promising. Let's see. Edit 2: Maybe #935 (comment) could make the code above obsolete as well. |
I've created a full working example. |
Thank you. I'll take a look at it. Looks promising from the first glance! |
Thanks! The initial commit was buggy. I gave it a polish. ;)
… On 25 Jun 2021, at 14:38, Stefan Natter ***@***.***> wrote:
I've created a full working example <https://github.com/Piepongwong/gatsby_nextjs_storybook_i18n_scaffolding>.
Thank you. I'll take a look at it. Looks promising from the first glance!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#1012 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AFOHDJY5DVMNQ6V6CVLY6F3TUR2DXANCNFSM4YQ4JVCQ>.
|
Hi @Piepongwong, I was not able to apply your solution in my setup. :/ I'll post an issue in your repo. |
@jtonneyck you are life saver. With Next 12.2 (Tailwind + TS) and your repo the provided example didn't want to work out of the box, so after the following adjustments I got it flying. Hope this helps someone:
Please do follow the scaffolding repo before you apply my changes, focus especially on packages installed in package.json. What I changed there, I moved all of them to dev dependencies. Important detail:
Translations stop working. Source: https://storybook.js.org/addons/storybook-react-i18next This worked, however I struggle to comprehend why:
and the console error is expected:
|
For anyone that comes here there is an update to the webpack where In
|
I was already confused trying to understand why it didn't work, you saved my day. |
Could you add an example for storybook in the example folder?
I got it working for v7 but with v8 I get errors (
Can't resolve 'fs'
).This is probably because I have not set it up correctly, but I couldn't find a good example on how it should be initialized in storybook.
The text was updated successfully, but these errors were encountered: