smrq / babel-plugin-require-context-hook

Babel plugin to replicate Webpack require.context
47 stars 14 forks source link

Compilation issue with storybook #2

Closed moimael closed 6 years ago

moimael commented 6 years ago

Hi,

I'm trying to use this plugin with storybook and I get a compile error each time. I followed the readme to set up the plugin.

Here is what I get:

WARNING in ./node_modules/babel-plugin-require-context-hook/register.js 34:9-25
Critical dependency: the request of a dependency is an expression
 @ ./.storybook/config.js
 @ multi ./node_modules/@storybook/core/dist/server/config/polyfills.js ./node_modules/@storybook/core/dist/server/config/globals.js ./.storybook/config.js ./node_modules/webpack-hot-middleware/client.js?reload=true

ERROR in ./node_modules/babel-plugin-require-context-hook/register.js
Module not found: Error: Can't resolve 'fs' in '/home/mlavault/Development/portal/node_modules/babel-plugin-require-context-hook'
 @ ./node_modules/babel-plugin-require-context-hook/register.js 8:12-25
 @ ./.storybook/config.js
 @ multi ./node_modules/@storybook/core/dist/server/config/polyfills.js ./node_modules/@storybook/core/dist/server/config/globals.js ./.storybook/config.js ./node_modules/webpack-hot-middleware/client.js?reload=true
ℹ 「wdm」: Failed to compile.
a7ul commented 6 years ago

👍 I am facing the exact same issue aswell.

beeequeue commented 6 years ago

We're also having the same issue. 😄

hazzadous commented 6 years ago

Looks like you are adding babel-plugin-require-context-hook/register to .storybook/config.js. request.context should be available if you're using webpack so you shouldn't need the register call. If you're trying to get it working with jest as I was then put the register call in jest_setup.js as in https://github.com/storybooks/storybook/tree/master/addons/storyshots/storyshots-core#configure-jest-to-work-with-webpacks-requirecontext instead.

smrq commented 6 years ago

Although I personally do not use this with Storybook, this sounds exactly like you are trying to apply this plugin to a Webpack bundle instead of executing in Node. You don't need this plugin in Webpack; it's a polyfill for Webpack behavior in Node!

Thanks to @hazzadous for the link. If you still can't figure things out, you should probably ask someone from Storybook instead, as the problem is in your Storybook configuration, not within this plugin.