You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I have a lerna monorepo, where there can be nested node_modules folders inside packages.
I also have storybook setup in the same repo, though it is outside of lerna packages and hence not managed by lerna.
I have a custom webpack pipeline which is different from the default storybook webpack config (because I need to have a setup for using css-modules, postcss-loader etc).
But I am also using storybook Docs, for which i need to have some babel-loader setup which can cater to react-docgen. Since storybook webpack config already has this by default, I am just merging my config with storybook webpack config, to pickup whatever i require from storybook config. This might not be the best way to customize webpack config, but stay with me.
This is how my ./storybook/webpack.config.js looks like:
So, I have my own webpack pipeline for styles, and I am picking up the babel-loader and source-loader from default storybook webpack config.
This setup works fine, stories are rendered correctly and docs work as well.
Recently, when I tried to write stories for a component inside a package which has its own node_modules, I got an error related to
exports is not defined
This was from the nested node_modules folder.
With some research, I was able to figure out that this might be happening because webpack is transpiling the nested node_modules folder (although I am not sure why transpiling the node_modules shouldn't work, i know it is not recommended, but not sure if it should break after transpiling https://stackoverflow.com/questions/54156617/why-would-we-exclude-node-modules-when-using-babel-loader)
The research was mostly related to the fact that removing the nested node_modules folder, but having the dependencies in the top level node_modules folder works, which lead me to believe that somehow these 2 node_modules folders are being treated differently. I was not able to exclude it by overriding it in my custom webpack config and changing the order of merge, because i was not overriding or updating the default storybook babel-laoder config directly, So, i tried to look into the storybook webpack config to see if I can do something there.
There are multiple ways to make it work:
as suspected, the nested node_modules is not excluded by storybook webpack config by default, so If i copy the storybook webpack config for babel-laoder and change it to exclude the nested node_modules it works.
I have just added @babel/plugin-transform-modules-commonjs in plugins
I don't believe that i should need to use this.
if I just create an empty babel.config.js inside the storybook folder, it works, without changing anything else. OR even if i copy the exact same babel.config.js as the parent folder to storybook folder, it works. I suspect this is due to some faulty setup for reading babel.config.js in storybook ?
[ ] This is something I don't understand. How does this solve the issue without changing anything else?
If I change useBuiltIns: 'usage' to useBuiltIns: 'entry' in storybook babel-loaderpreset-env, it works without any other changes. This leads me to believe that storybook is using some babel polyfills which are somehow interfering with the transpiled node_modules
[ ] This is something I don't understand. How does this solve the issue without changing anything else?
Expected behavior
I expected that:
transpiling of node_modules shouldn't be a problem and shouldn't lead to this error. But that is more related to webpack.
the behaviour should not change by just changing useBuiltIns: usage to useBuiltIns: entry. This might be more related to webpack than storybook.
if adding a new babel.config.js at storybook level works, i would have expected that if I remove the parent babel.config.js it should also work, but that doesn't work.
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!
Describe the bug
I have a lerna monorepo, where there can be nested
node_modules
folders insidepackages
.I also have storybook setup in the same repo, though it is outside of lerna packages and hence not managed by lerna.
I have a custom webpack pipeline which is different from the default storybook webpack config (because I need to have a setup for using css-modules, postcss-loader etc).
But I am also using storybook Docs, for which i need to have some
babel-loader
setup which can cater toreact-docgen
. Since storybook webpack config already has this by default, I am just merging my config with storybook webpack config, to pickup whatever i require from storybook config. This might not be the best way to customize webpack config, but stay with me.This is how my
./storybook/webpack.config.js
looks like:So, I have my own webpack pipeline for styles, and I am picking up the
babel-loader
andsource-loader
from default storybook webpack config.This setup works fine, stories are rendered correctly and docs work as well.
Recently, when I tried to write stories for a component inside a package which has its own node_modules, I got an error related to
exports is not defined
This was from the nested node_modules folder.
With some research, I was able to figure out that this might be happening because webpack is transpiling the nested node_modules folder (although I am not sure why transpiling the node_modules shouldn't work, i know it is not recommended, but not sure if it should break after transpiling
https://stackoverflow.com/questions/54156617/why-would-we-exclude-node-modules-when-using-babel-loader)
The research was mostly related to the fact that removing the nested
node_modules
folder, but having the dependencies in the top levelnode_modules
folder works, which lead me to believe that somehow these 2 node_modules folders are being treated differently. I was not able to exclude it by overriding it in my custom webpack config and changing the order of merge, because i was not overriding or updating the default storybook babel-laoder config directly, So, i tried to look into the storybook webpack config to see if I can do something there.There are multiple ways to make it work:
as suspected, the nested node_modules is not excluded by storybook webpack config by default, so If i copy the storybook webpack config for babel-laoder and change it to exclude the nested node_modules it works.
This is something i understand
I have added the 'appdir/packages/components/node_modules', in exclude, and this works.
babel.config.js
, it works, probably because now it can transpile the nestednode_modules
appropriately ?[ ] This is something I don't understand, ie, why is transpiling node_modules a problem ?
I have just added @babel/plugin-transform-modules-commonjs in plugins
I don't believe that i should need to use this.
if I just create an empty
babel.config.js
inside the storybook folder, it works, without changing anything else. OR even if i copy the exact samebabel.config.js
as the parent folder to storybook folder, it works. I suspect this is due to some faulty setup for readingbabel.config.js
in storybook ?[ ] This is something I don't understand. How does this solve the issue without changing anything else?
If I change
useBuiltIns: 'usage'
touseBuiltIns: 'entry'
in storybookbabel-loader
preset-env
, it works without any other changes. This leads me to believe that storybook is using some babel polyfills which are somehow interfering with the transpiled node_modules[ ] This is something I don't understand. How does this solve the issue without changing anything else?
Expected behavior
I expected that:
Screenshots
added in problem description
Code snippets
added in problem description
System:
Environment Info:
System:
OS: macOS Mojave 10.14.6
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Binaries:
Node: 12.11.1 - /usr/local/bin/node
Yarn: 1.19.1 - /usr/local/bin/yarn
npm: 6.11.3 - /usr/local/bin/npm
Browsers:
Chrome: 83.0.4103.106
Firefox: 75.0
Safari: 13.1.1
More Info
This is the default storybook config rules I am getting by
console.log(JSON.stringify(config.module.rules))
The text was updated successfully, but these errors were encountered: